63 Star 183 Fork 3

Gitee 极速下载/hyperledger-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
sched.go 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package server
import "time"
type durationSeries func() time.Duration
// ticker has a channel that will send the
// time with intervals computed by the durationSeries.
type ticker struct {
stopped bool
C <-chan time.Time
nextInterval durationSeries
stopChan chan struct{}
}
// newTicker returns a channel that sends the time at periods
// specified by the given durationSeries.
func newTicker(nextInterval durationSeries) *ticker {
c := make(chan time.Time)
ticker := &ticker{
stopChan: make(chan struct{}),
C: c,
nextInterval: nextInterval,
}
go func() {
defer close(c)
ticker.run(c)
}()
return ticker
}
func (t *ticker) run(c chan<- time.Time) {
for {
if t.stopped {
return
}
select {
case <-time.After(t.nextInterval()):
t.tick(c)
case <-t.stopChan:
return
}
}
}
func (t *ticker) tick(c chan<- time.Time) {
select {
case c <- time.Now():
case <-t.stopChan:
t.stopped = true
}
}
func (t *ticker) stop() {
close(t.stopChan)
}
func exponentialDurationSeries(initialDuration, maxDuration time.Duration) func() time.Duration {
exp := &exponentialDuration{
n: initialDuration,
max: maxDuration,
}
return exp.next
}
type exponentialDuration struct {
n time.Duration
max time.Duration
}
func (exp *exponentialDuration) next() time.Duration {
n := exp.n
exp.n *= 2
if exp.n > exp.max {
exp.n = exp.max
}
return n
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/hyperledger-fabric.git
git@gitee.com:mirrors/hyperledger-fabric.git
mirrors
hyperledger-fabric
hyperledger-fabric
v1.4.8

搜索帮助

0d507c66 1850385 C8b1a773 1850385