Documentation ¶
Overview ¶
Package errorcontext implements a Context that can be canceled with a specific error instead of the usual context.Canceled.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CancelFunc ¶
type CancelFunc func(error)
CancelFunc extends the regular context.CancelFunc with an error argument
type ErrorContext ¶
ErrorContext can be used to attach errors to a context cancelation.
Example ¶
package main import ( "go.thethings.network/lorawan-stack/v3/pkg/errorcontext" "go.thethings.network/lorawan-stack/v3/pkg/util/test" ) var err error func main() { ctx, cancel := errorcontext.New(test.Context()) defer cancel(nil) go func() { for { // do work if err != nil { cancel(err) } } }() for { select { // case data := <-dataChan: case <-ctx.Done(): return } } }
Output:
func (*ErrorContext) Cancel ¶
func (c *ErrorContext) Cancel(err error)
Cancel the ErrorContext with an error. The context can not be re-used or re-canceled after this function is called.
func (*ErrorContext) Err ¶
func (c *ErrorContext) Err() error
Err returns the err of the ErrorContext if non-nil, or the error of the underlying Context.
Click to show internal directories.
Click to hide internal directories.