Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrStopped = errors.New("nursery is stopping or stopped")
Functions ¶
func Open ¶
func Open(ctx context.Context, init Initializer) error
Open creates a new Nursery that can be used to start Tasks. All started Tasks are guaranteed to be completed by the time Open returns. In terms of the Go memory model, all Tasks "synchronize before" Open can complete.
Example ¶
package main import ( "context" "errors" "fmt" "time" "github.com/jsocol/nursery" ) func main() { ctx := context.Background() err := nursery.Open(ctx, func(n nursery.Nursery) error { n.Start(func(ctx context.Context) error { return errors.New("I always fail") }) n.Start(func(ctx context.Context) error { time.Sleep(time.Millisecond) fmt.Println("I always happen") return nil }) return nil }) if err != nil { fmt.Println("Err: " + err.Error()) } }
Output: I always happen Err: I always fail
Types ¶
type Initializer ¶
Click to show internal directories.
Click to hide internal directories.