package main
import (
"bytes"
"encoding/json"
"fmt"
"time"
"github.com/zqkgo/debounce-pool"
)
func main() {
p := debounce.NewPool(1000)
call1 := p.Get("key1", time.Second)
call2 := p.Get("key2", 2*time.Second)
var n1 int
for i := 0; i < 100; i++ {
call1(func() {
n1++
})
}
var n2 int
for i := 0; i < 100; i++ {
call2(func() {
n2++
})
}
// wait for call1 to actually execute
time.Sleep(time.Second)
fmt.Println(n1 == 1) // true
fmt.Println(n2 == 1) // false
// wait for call2 to actually execute
time.Sleep(2 * time.Second)
fmt.Println(n2 == 1) // true
}
-
Notifications
You must be signed in to change notification settings - Fork 0
zqkgo/debounce-pool
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
a pool manager for reusing debounce func
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published