mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
test: update test for Schedule
This commit is contained in:
1 parent
0f9764f41e
commit
5c580ed013
2 files changed
+29
-15
No files matched your search
@@ -164,16 +164,18 @@ func Throttle(fn func(), interval time.Duration) func() {
|
||||
|
||||
// Schedule invoke function every duration time, util close the returned bool channel.
|
||||
// Play: https://go.dev/play/p/hbON-Xeyn5N
|
||||
func Schedule(d time.Duration, fn any, args ...any) chan bool {
|
||||
func Schedule(duration time.Duration, fn any, args ...any) chan bool {
|
||||
// Catch programming error while constructing the closure
|
||||
mustBeFunction(fn)
|
||||
|
||||
quit := make(chan bool)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
unsafeInvokeFunc(fn, args...)
|
||||
|
||||
select {
|
||||
case <-time.After(d):
|
||||
case <-time.After(duration):
|
||||
case <-quit:
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user