Skip to content

qustavo/delay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

delay Build Status

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

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)
	}

}

About

Delay goroutines at will

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages