MCPcopy
hub / github.com/rs/zerolog / NewWaiter

Function NewWaiter

diode/internal/diodes/waiter.go:30–51  ·  view source on GitHub ↗

NewWaiter returns a new Waiter that wraps the given diode.

(d Diode, opts ...WaiterConfigOption)

Source from the content-addressed store, hash-verified

28
29// NewWaiter returns a new Waiter that wraps the given diode.
30func NewWaiter(d Diode, opts ...WaiterConfigOption) *Waiter {
31 w := new(Waiter)
32 w.Diode = d
33 w.c = sync.NewCond(&w.mu)
34 w.ctx = context.Background()
35
36 for _, opt := range opts {
37 opt(w)
38 }
39
40 go func() {
41 <-w.ctx.Done()
42
43 // Mutex is strictly necessary here to avoid a race in Next() (between
44 // w.isDone() and w.c.Wait()) and w.c.Broadcast() here.
45 w.mu.Lock()
46 w.c.Broadcast()
47 w.mu.Unlock()
48 }()
49
50 return w
51}
52
53// Set invokes the wrapped diode's Set with the given data and uses Broadcast
54// to wake up any readers.

Callers 1

NewWriterFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected