github.com/haraldrudell/parl@v0.4.176/iters/cancel-states.go (about)

     1  /*
     2  © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package iters
     7  
     8  import "fmt"
     9  
    10  const (
    11  	// iteration is in progress
    12  	notCanceled cancelStates = iota
    13  	// consumer has invoked Cancel
    14  	cancelRequested
    15  	// cancel was successfully requested from the iterator-value
    16  	// producer
    17  	cancelComplete
    18  	// end-of-data notice received from value-producer,
    19  	// typically by returning parl.ErrEndCallbacks
    20  	endOfData
    21  	// value-producer returned error other than parl.ErrEndCallbacks
    22  	errorReceived
    23  	// iteratorAction had panic
    24  	panicked
    25  )
    26  
    27  // notCanceled cancelRequested cancelComplete endOfData errorReceived
    28  type cancelStates uint32
    29  
    30  var cancelStatesMap = map[cancelStates]string{
    31  	notCanceled:     "notCanceled",
    32  	cancelRequested: "cancelRequested",
    33  	cancelComplete:  "cancelComplete",
    34  	endOfData:       "endOfData",
    35  	errorReceived:   "errorReceived",
    36  	panicked:        "panic",
    37  }
    38  
    39  func (s cancelStates) String() (s2 string) {
    40  	if s2 = cancelStatesMap[s]; s2 != "" {
    41  		return
    42  	}
    43  	s2 = fmt.Sprintf("?badCancelState:%d", s)
    44  
    45  	return
    46  }