golang parallel 介绍
一个golang并行编程库,用于业务聚合或重构。可以用最少的代码,将串行的函数调用并行化,无需改变函数的声明。
实现原理和demo参考github地址:https://github.com/buptmiao/parallel
使用:
以下有三种方法:testjoba,testjobb,testjobc执行并行:
import ( "github.com/buptmiao/parallel" ) func testJobA() string { return "job" } 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(&s) p.Register(testJobB, 1, 2).SetReceivers(&x) p.Register(testJobC, 3).SetReceivers(&y) // block here p.Run() if s != "job" || x != 3 || y != -3{ panic("unexpected result") } }
golang parallel 官网
https://github.com/buptmiao/parallel
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。