1 Star 0 Fork 0

CaptialSTeam/ubdframe

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
comag.go 848 Bytes
一键复制 编辑 原始数据 按行查看 历史
Souki 提交于 2024-12-17 08:59 +08:00 . !1初始化
package comag
import (
"fmt"
"golang.org/x/net/context"
"time"
)
type CoFunc func(context.Context)
func debugPrint(msg string, params ...interface{}) {
if len(params) <= 0 {
fmt.Println(msg)
return
}
fmt.Printf(msg+"\n", params...)
}
func DemoCoA(ctx context.Context) {
errCh := ctx.Value("error").(chan error)
for i := 1; i <= 100; i++ {
select {
case <-ctx.Done():
debugPrint("input Done by ctx: %s", ctx.Err())
return
default:
if i > 10 {
errCh <- fmt.Errorf("input error")
return
}
debugPrint("input:%d", i)
time.Sleep(time.Second)
}
}
}
func DemoCoB(ctx context.Context) {
for i := 1; i <= 100; i++ {
select {
case <-ctx.Done():
debugPrint("out Done by ctx: %s", ctx.Err())
return
default:
debugPrint("out:%d", i)
time.Sleep(time.Second)
}
}
debugPrint("out Done")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/captials-team/ubdframe.git
git@gitee.com:captials-team/ubdframe.git
captials-team
ubdframe
ubdframe
v1.0.2

搜索帮助