waiter

package
v1.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 2 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Waiter

type Waiter interface {
	// Wait blocks until the signal is broadcast.
	// If the return value is false no more events will be broadcast.
	Wait() bool
	// Stop removes the waiter from the WaiterGroup.
	// Future calls to Wait will return false immediately.
	Stop()
}

Waiter waits for a signal to be broadcast.

type WaiterGroup

type WaiterGroup struct {
	// contains filtered or unexported fields
}

WaiterGroup provides a mechanism to notify multiple goroutines of the occurrence of events. WaiterGroup can be thought of as the inverse of sync.WaitGroup, instead of waiting for a group of goroutines to finish, WaiterGroup unblocks a group of waiting goroutines.

Example:

g := NewGroup()
// Always call stop when it is no longer needed.
defer g.Stop()
w := g.NewWaiter()
go func() {
    // Block until the broadcast.
    for w.Wait() {
        // ... do something now that event has occurred ...
    }
}()
g.Broadcast()

func NewGroup

func NewGroup() *WaiterGroup

NewGroup returns a new WaiterGroup, which must be stopped when it is no longer needed.

func (*WaiterGroup) Broadcast

func (g *WaiterGroup) Broadcast()

Broadcast signal that the event has occurred and unblocks all waiting goroutines.

func (*WaiterGroup) NewWaiter

func (g *WaiterGroup) NewWaiter() (Waiter, error)

NewWaiter creates and returns a new waiter for the group. An error is returned if the group is stopped.

If NewWaiter is called concurrently with Broadcast there is no guarantee that all broadcast messages are sent to all Waiters.

func (*WaiterGroup) Stop

func (g *WaiterGroup) Stop()

Stop unblocks all waiting goroutines. Stop must be called when the group is no longer needed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL