github.com/haraldrudell/parl@v0.4.176/err-end-callbacks.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 import ( 9 "errors" 10 ) 11 12 // ErrEndCallbacks indicates upon retun from a callback function that 13 // no more callbacks are desired 14 // - ErrEndCallbacks does not indicate an error and should not be returned 15 // by any other function than a callback 16 // - check for ErrrEndCallback is using the [errors.Is] method with the 17 // [parl.ErrEndCallbacks] value 18 // - EndCallbacks creates an ErrEndCallbacks value basd on another error 19 // - — 20 // - an ErrEndCallbacks type implements: 21 // - — an Is method returning true for errors implementing a EndCallbacks method 22 // - parl.ErrEndCallbacks additionally implements: 23 // - — a dummy EndCallbacks method 24 // 25 // Usage: 26 // 27 // func callback() (err error) { 28 // return parl.ErrEndCallbacks 29 // 30 // if errors.Is(err, parl.ErrEndCallbacks) { 31 // err = nil 32 // … 33 var ErrEndCallbacks = EndCallbacks(errors.New("end callbacks error")) 34 35 // EndCallbacks creates a EndCallbacks error based on another error 36 func EndCallbacks(err error) (err2 error) { return &endCallbacks{err} } 37 38 // endCallbacks is the named type of [parl.ErrEndCallbacks] value 39 type endCallbacks struct{ error } 40 41 var _ = errors.Is 42 43 // Is indicates that endCallbacks type is EndCallBack 44 func (e *endCallbacks) Is(err error) (is bool) { 45 _, is = err.(interface{ EndCallbacks() }) 46 return 47 } 48 49 // dummy EndCallbacks method 50 func (e *endCallbacks) EndCallbacks() {}