github.com/haraldrudell/parl@v0.4.176/nb-chan-wait-for-close.go (about)

     1  /*
     2  © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package parl
     7  
     8  // WaitForClose blocks until the channel is closed and empty
     9  //   - if Close is not invoked or the channel is not read to end,
    10  //     WaitForClose blocks indefinitely
    11  //   - if CloseNow is invoked, WaitForClose is unblocked
    12  //   - if errp is non-nil, any thread and close errors are appended to it
    13  //   - a close error will already have been returned by Close
    14  //   - thread-safe, panic-free, deferrable
    15  func (n *NBChan[T]) WaitForClose(errp ...*error) {
    16  	defer n.appendErrors(nil, errp...)
    17  
    18  	<-n.waitForClose.Ch()
    19  }
    20  
    21  // WaitForCloseCh returns a channel that closes when [NBChan.Ch] closes
    22  //   - the underlying channel is sending items, this channel is not
    23  func (n *NBChan[T]) WaitForCloseCh() (ch AwaitableCh) { return n.waitForClose.Ch() }