A simple, lightweight signaling mechanism in Go.
Flare provides an alternative to the standard context package in Go for signaling goroutines, without carrying cancellation info or other values. It's a minimalistic tool designed to provide a straightforward mechanism to signal goroutines to stop their work.
go get github.com/twiny/flare
package main
import (
"github.com/twiny/flare"
)
func main() {
n := flare.NewNotifier()
// Spawn a goroutine
go func() {
select {
case <-n.Hold():
return
default:
// Do some work
}
}()
// Signal the goroutine to stop
n.Signal()
}
func main() {
n, cancel := flare.NewNotifierWithCancel(context.Background())
// Canceling the context will also signal the flare Notifier.
defer cancel()
// Spawn a goroutine
go func() {
select {
case <-n.Hold():
return
default:
// Do some work
}
}()
// Signal the goroutine to stop
n.Signal()
}
More documentation can be found in the wiki.
Bugs or suggestions? Please visit the issue tracker.