golang parallel golang 并行编程库 golang parallel

agolangf • 2039 次点击    
这是一个分享于 的项目,其中的信息可能已经有所发展或是发生改变。
一个golang并行编程库,用于业务聚合或重构。可以用最少的代码,将串行的函数调用并行化,无需改变函数的声明。 实现原理和demo参考github地址:[https://github.com/buptmiao/parallel](https://github.com/buptmiao/parallel) **使用:** 以下有三种方法:testjoba,testjobb,testjobc执行并行: <pre class="brush:cpp ;toolbar: true; auto-links: false;">import (     &#34;github.com/buptmiao/parallel&#34; ) func testJobA() string {     return &#34;job&#34; } func testJobB(x, y int) int {     return x + y } func testJobC(x int) int {     return -x } func main() {     var s string     var x, y int     p := parallel.NewParallel()     p.Register(testJobA).SetReceivers(&amp;s)     p.Register(testJobB, 1, 2).SetReceivers(&amp;x)     p.Register(testJobC, 3).SetReceivers(&amp;y)     // block here     p.Run()     if s != &#34;job&#34; || x != 3 || y != -3{         panic(&#34;unexpected result&#34;)     } }</pre>
授权协议:
MIT
开发语言:
Google Go 查看源码»
操作系统:
跨平台
2039 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传