github.com/haraldrudell/parl@v0.4.176/once-do.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  // onceDo provides a wrapper method
     9  // that invokes doFuncArgument and then sets isDone to true
    10  //   - onceDo is a tuple value-type
    11  //   - — if used as local variable, function argument or return value,
    12  //     no allocation tajkes place
    13  //   - — taking its address causes allocation
    14  type onceDo struct {
    15  	doFuncArgument func()
    16  	// pointer to observable parl.Once
    17  	//	- has isDone field
    18  	*Once
    19  }
    20  
    21  // invokeF is behind o.once
    22  //   - after doFuncArgument invocation, it sets isDone to true
    23  //   - isDone provides observability
    24  func (d *onceDo) invokeF() {
    25  	defer d.isDone.Store(true)
    26  
    27  	d.doFuncArgument()
    28  }