Documentation ¶
Overview ¶
A barrier primitive which can be used to signal a permanent state change, for example to signal that shutdown should occur.
golang-nuts mailing list discussion: https://groups.google.com/d/topic/golang-nuts/RBQjg6YOiWA/discussion
Example:
package main import ( "sync" "github.com/pwaller/barrier" ) func main() { var w sync.WaitGroup defer w.Wait() // Main should wait for its goroutines var b barrier.Barrier w.Add(1) go func() { defer w.Done() defer b.Fall() println("GO!") <-b.Barrier() // Many goroutines can wait on the barrier }() w.Add(1) go func() { defer w.Done() defer b.Fall() println("GO!") // When this goroutine happens to return, // all barrier waits can be passed. return }() }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Barrier ¶
type Barrier struct { // An optional hook, which if set, is called exactly once when the first // b.Fall() is invoked. FallHook func() // contains filtered or unexported fields }
The zero of Barrier is a ready-to-use value
func (*Barrier) Barrier ¶
func (b *Barrier) Barrier() <-chan struct{}
When `b.Fall()` is called, the channel returned by Barrier() is closed (and becomes always readable)
Click to show internal directories.
Click to hide internal directories.