We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
语鹊的文档地址:https://www.yuque.com/tal-tech/go-zero/zig6zy
文中说的“带上 dts.insertExecutor.Wait(),当然要等待全部的 goroutine task 完成”,我做了个实验,代码如下: executor := executors.NewBulkExecutor( myExecutor, executors.WithBulkInterval(time.Second*3), // 3s会自动刷一次container中task去执行 executors.WithBulkTasks(16), // container最大task数。一般设为2的幂次 ) for i := 0; i < 20; i++ { executor.Add(i) } executor.Wait() // time.Sleep(10 * time.Second) // executor.Flush() 如果把executor.Flush()注释掉,只会打印出0到15,进程就退出了,剩下的任务就丢失了。因为periodicalexecutor.go里的 pe.waitGroup.Add(1) 是在子协程里调用的,所以调用了executor.Wait()主协程也等不到子协程到ticker的时间自动去flush就退出了,所以16到20的任务就丢失了。在主协程调用executor.Flush(),其实是把剩下的任务取出到了主协程来执行了,如果忘了的话就会丢任务。或者主协程执行的时间足够长,能让子协程达到ticker的时间自动去flush。
The text was updated successfully, but these errors were encountered:
fix issue #186
7d7cb83
fixed.
Flush first in Wait.
Sorry, something went wrong.
fix issue zeromicro#186
a728507
c646b81
No branches or pull requests
语鹊的文档地址:https://www.yuque.com/tal-tech/go-zero/zig6zy
文中说的“带上 dts.insertExecutor.Wait(),当然要等待全部的 goroutine task 完成”,我做了个实验,代码如下:
executor := executors.NewBulkExecutor(
myExecutor,
executors.WithBulkInterval(time.Second*3), // 3s会自动刷一次container中task去执行
executors.WithBulkTasks(16), // container最大task数。一般设为2的幂次
)
for i := 0; i < 20; i++ {
executor.Add(i)
}
executor.Wait()
// time.Sleep(10 * time.Second)
// executor.Flush()
如果把executor.Flush()注释掉,只会打印出0到15,进程就退出了,剩下的任务就丢失了。因为periodicalexecutor.go里的 pe.waitGroup.Add(1) 是在子协程里调用的,所以调用了executor.Wait()主协程也等不到子协程到ticker的时间自动去flush就退出了,所以16到20的任务就丢失了。在主协程调用executor.Flush(),其实是把剩下的任务取出到了主协程来执行了,如果忘了的话就会丢任务。或者主协程执行的时间足够长,能让子协程达到ticker的时间自动去flush。
The text was updated successfully, but these errors were encountered: