github.com/haraldrudell/parl@v0.4.176/if-waitable.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  // Waitable is the invoker’s Wait part of sync.WaitGroup and
     9  // other implementations.
    10  // Waitable is a many-to-many relation.
    11  // Waitable allows the caller to await exit and free of all invocations.
    12  //
    13  //	waitsForLots parl.WaitGroup
    14  //	shutsDownLots parl.OnceChan
    15  //	… = NewSomething(&waitsForLots, &shutsDownLots)
    16  //	go someThread(&waitsForLots, &shutsDownLots)
    17  //	func someThread(Doneable w, context.Context ctx) {
    18  //	  defer w.Done()
    19  //	  w.Add(2)
    20  //	  go somethingElse()
    21  type Waitable interface {
    22  	Wait() // similar to sync.WaitGroup.Wait()
    23  }
    24  
    25  // SyncWait provides sync.WaitGroup.Wait()
    26  type SyncWait interface {
    27  	Wait()
    28  }
    29  
    30  // SyncWait provides sync.WaitGroup.Add()
    31  type SyncAdd interface {
    32  	Add(delta int)
    33  }
    34  
    35  // SyncDone provides sync.WaitGroup.Done()
    36  type SyncDone interface {
    37  	Done()
    38  }
    39  
    40  type WaitedOn interface {
    41  	SyncAdd
    42  	SyncDone
    43  	DoneBool() (isExit bool)
    44  	IsZero() (isZero bool)
    45  }
    46  
    47  type WaitingFor interface {
    48  	SyncAdd
    49  	IsZero() (isZero bool)
    50  	Counters() (adds, dones int)
    51  	SyncWait
    52  	String() (s string)
    53  }
    54  
    55  // waiter allows to use any of observable parl.WaitGroup or parl.TraceGroup
    56  type Waiter interface {
    57  	WaitedOn
    58  	WaitingFor
    59  }
    60  
    61  type ErrorManager interface {
    62  	Ch() (ch <-chan GoError)
    63  }
    64  
    65  type ErrorCloser interface {
    66  	InvokeIfError(addError func(err error))
    67  	Close()
    68  }
    69  
    70  // Doneable is the callee part of sync.Waitgroup
    71  // and other implementations
    72  // Doneable is a many-to-many relation.
    73  // Doneable allows the callee to instatiate and invoke any number
    74  // of things that are awaitable by the caller.
    75  //
    76  //	… = NewSomething(&waitsForLots, &shutsDownLots)
    77  //	go someThread(&waitsForLots, &shutsDownLots)
    78  //	func someThread(Doneable w, context.Context ctx) {
    79  //	  defer w.Done()
    80  //	  w.Add(2)
    81  //	  go somethingElse()
    82  type Doneable interface {
    83  	Add(delta int)
    84  	Done()
    85  }