Documentation ¶
Overview ¶
Package goroutine provides a simple way to manage goroutines and facilitate their graceful shutdown.
Example ¶
// This function does the actual work. // In this example, we're not using the Context, but you really always should. worker := func(_ context.Context) { time.Sleep(100 * time.Millisecond) } goroutines := New() // Start a new goroutine. goroutines.Go(context.Background(), worker) // Cancel all goroutines' contexts, and wait for them to finish. _ = goroutines.CancelAll(context.Background(), true)
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Goroutines ¶
type Goroutines struct {
// contains filtered or unexported fields
}
Goroutines manages a collection of goroutines.
func (*Goroutines) AwaitTermination ¶
func (gs *Goroutines) AwaitTermination(ctx context.Context) error
AwaitTermination waits for all goroutines to finish. Returns ctx.Err() if ctx is canceled while waiting, or nil otherwise.
Click to show internal directories.
Click to hide internal directories.