github.com/haraldrudell/parl@v0.4.176/once-waiter-ro.go (about)

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