1 Star 0 Fork 0

peter / fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
batch_util.go 924 Bytes
一键复制 编辑 原始数据 按行查看 历史
manish 提交于 2018-03-12 16:19 . [FAB-7692] Refactor statecouchdb impl
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package statecouchdb
import (
"sync"
)
// batch is executed in a separate goroutine.
type batch interface {
execute() error
}
// executeBatches executes each batch in a separate goroutine and returns error if
// any of the batches return error during its execution
func executeBatches(batches []batch) error {
logger.Debugf("Executing batches = %s", batches)
numBatches := len(batches)
if numBatches == 0 {
return nil
}
if numBatches == 1 {
return batches[0].execute()
}
var batchWG sync.WaitGroup
batchWG.Add(numBatches)
errsChan := make(chan error, numBatches)
defer close(errsChan)
for _, b := range batches {
go func(b batch) {
defer batchWG.Done()
if err := b.execute(); err != nil {
errsChan <- err
return
}
}(b)
}
batchWG.Wait()
if len(errsChan) > 0 {
return <-errsChan
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/peter_code_git/fabric.git
git@gitee.com:peter_code_git/fabric.git
peter_code_git
fabric
fabric
v1.2.0

搜索帮助