Implementing a workers pool when dealing with reading and fetching

blov · · 459 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<h2>First of all, I need to fetch 4 images and apply them on a canvas images. Here&#39;s what I&#39;m working with</h2> <p>readCanvas() -&gt; async, returns []byte </p> <p>fetchImg() -&gt; async, returns []byte</p> <h2>applyOnCavas(canvas, img []byte, options struct{}) -&gt; non blocking, returns []byte</h2> <p>What I&#39;m looking to do with the following. Start reading the canvas and fetching the images one by one all in the same time. When a fetch is done, apply the fetched image directly on the canvas and assign the new []byte result. So on until all the fetching is done. I&#39;ve been reading about how a working pool example works, but really couldn&#39;t grasp it yet. There&#39;s also sync.Pool.</p> <p>Just looking for a basic example that could help me start it out, thnaks!</p> <hr/>**评论:**<br/><br/>epiris: <pre><p>I just made a post a little bit ago that may <a href="https://www.reddit.com/r/golang/comments/70fjlm/kill_child_goroutines_on_sigkill_detect_main/dn37mc2/" rel="nofollow">help</a>, here&#39;s the <a href="https://gist.github.com/cstockton/77e38b16999f382fa0ef3060d785413a" rel="nofollow">example</a>. You could start by editing he Worker func to &#34;fetch&#34; and change the channel to be a structure that contains a []byte field of image data as well as a field the result collector can use to correlate the byte to relevant metadata or embed the metadata directly if it&#39;s just a x, y coord. Then instead of appending to alphabet you would just applyOnCanvas.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

459 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传