-
Notifications
You must be signed in to change notification settings - Fork 1
/
once-waiter-ro.go
33 lines (27 loc) · 1.09 KB
/
once-waiter-ro.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
© 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
ISC License
*/
package parl
import (
"context"
"github.com/haraldrudell/parl/perrors"
)
// OnceWaiterRO allows any number of threads to wait for a single next occurrence.
// OnceWaiterRO is a OnceWaiter without the Cancel method
type OnceWaiterRO struct {
ow OnceWaiter
}
// NewOnceWaiter returns a channel that will send one item
// when the context cancels or immediately if the context was already canceled.
func NewOnceWaiterRO(onceWaiter *OnceWaiter) (onceWaiterRO *OnceWaiterRO) {
if onceWaiter == nil {
panic(perrors.NewPF("onceWaiter cannot be nil"))
}
return &OnceWaiterRO{ow: *onceWaiter}
}
func (ow *OnceWaiterRO) Ch() (ch <-chan struct{}) { return ow.ow.Ch() }
func (ow *OnceWaiterRO) Done() (done <-chan struct{}) { return ow.ow.Done() }
func (ow *OnceWaiterRO) Wait() { ow.ow.Wait() }
func (ow *OnceWaiterRO) DidOccur() (didOccur bool) { return ow.ow.DidOccur() }
func (ow *OnceWaiterRO) Context() (ctx context.Context) { return ow.ow.Context() }