https://github.com/qustavo/delay
Delay goroutines at will
https://github.com/qustavo/delay
Last synced: 9 months ago
JSON representation
Delay goroutines at will
- Host: GitHub
- URL: https://github.com/qustavo/delay
- Owner: qustavo
- License: bsd-2-clause
- Created: 2014-12-27T19:42:32.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-12-30T11:37:12.000Z (about 11 years ago)
- Last Synced: 2025-04-10T05:14:57.440Z (9 months ago)
- Language: Go
- Size: 180 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
delay [](https://travis-ci.org/gchaincl/delay)
=====
Delay goroutines at will
Rationale
---
You're notifying events, say _follow_ on users, so followed users will get
notified when someone start following them, now imagine _someone_ follows
_someother_ and, immediately after, it unfollows, you don't want to send the
notification to the supposedly followed user.
`Delay` tries to solve that problem.
It allows to *delay* event triggering defining a waiting time.
While an event is waiting to be triggered it can be updated or even cancelled
(so it will never triggered).
Example
=====
```go
func main() {
delayer := NewDelayer(func(key, payload string) {
println(key, payload)
}, 2*time.Second)
delayer.Register("a", "Msg A")
delayer.Register("b", "Msg B")
delayer.Register("c", "Msg C")
delayer.Register("c", "Msg C1")
delayer.Register("c", "Msg C2")
delayer.Register("c", "Msg C3")
for {
println(delayer.Pending(), " currently in queue")
time.Sleep(1 * time.Second)
}
}
```