github.com/haraldrudell/parl@v0.4.176/iters/if-iterator-provider.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package iters 7 8 // IteratorFunction is the signature used by NewFunctionIterator 9 // - if isCancel true, it means this is the last invocation of IteratorFunction and 10 // IteratorFunction should release any resources. 11 // Any returned value is not used 12 // - IteratorFunction signals end of values by returning parl.ErrEndCallbacks. 13 // Any returned value is not used 14 // - if IteratorFunction returns error, it will not be invoked again. 15 // Any returned value is not used 16 // - IteratorFunction must be thread-safe 17 // - IteratorFunction is invoked by at most one thread at a time 18 type IteratorFunction[T any] func(isCancel bool) (value T, err error) 19 20 type SimpleIteratorFunc[T any] func() (value T, hasValue bool) 21 22 // ConverterFunction is the signature used by NewConverterIterator 23 // - ConverterFunction receives a key and returns the corresponding value. 24 // - if isCancel true, it means this is the last invocation of ConverterFunction and 25 // ConverterFunction should release any resources. 26 // Any returned value is not used 27 // - ConverterFunction signals end of values by returning parl.ErrEndCallbacks. 28 // Any returned value is not used 29 // - if ConverterFunction returns error, it will not be invoked again. 30 // Any returned value is not used 31 // - ConverterFunction must be thread-safe 32 // - ConverterFunction is invoked by at most one thread at a time 33 type ConverterFunction[K any, V any] func(key K, isCancel bool) (value V, err error) 34 35 type SimpleConverter[K any, V any] func(key K) (value V) 36 37 // IteratorAction is a delegated request from [iters.BaseIterator] 38 // - isCancel true requests cancel of iteration. 39 // No further invocations will occur. 40 // The iterator should release resources. 41 // The iterator may return an error 42 // - otherwise, the iterator can: 43 // - — return the next value 44 // - — return an error. No further invocations will occur 45 // - — return err == parl.ErrEndCallbacks requesting an end to iterations. 46 // No further invocations will occur 47 // ErrEndCallbacks error is not returned to the consumer 48 // - the returned value is used if: 49 // - — returned err is nil and 50 // - — provided isCancel was false and 51 // - — returned didCancel is false 52 // - isPanic indicates that err is the result of a panic. 53 // isPanic is only used if err is non-nil 54 type IteratorAction[T any] func(isCancel bool) (value T, err error)