Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDone ¶
IsDone returns ctx is already done or else.
Example ¶
package main import ( "fmt" "go.nanasi880.dev/x/context/contextutil" ) func main() { ctx, cancel := contextutil.NewCancel() fmt.Println(contextutil.IsDone(ctx)) cancel() fmt.Println(contextutil.IsDone(ctx)) }
Output: false true
func IsError ¶
IsError returns true, if err is context.Canceled or context.DeadlineExceeded.
Example ¶
package main import ( "context" "fmt" "go.nanasi880.dev/x/context/contextutil" ) func main() { fmt.Println(contextutil.IsError(nil)) fmt.Println(contextutil.IsError(context.Canceled)) fmt.Println(contextutil.IsError(context.DeadlineExceeded)) fmt.Println(contextutil.IsError(fmt.Errorf("context canceled"))) }
Output: false true true false
Types ¶
type CancelableContext ¶
CancelableContext is cancelable context.
Example ¶
package main import ( "fmt" "go.nanasi880.dev/x/context/contextutil" ) func main() { ctx := contextutil.NewCancelable() fmt.Println(ctx.IsDone()) ctx.Cancel() fmt.Println(ctx.IsDone()) }
Output: false true
func NewCancelable ¶
func NewCancelable() CancelableContext
NewCancelable is shorthand of NewCancelableContext(context.Background()).
func NewCancelableContext ¶
func NewCancelableContext(parent context.Context) CancelableContext
NewCancelableContext is creating new cancelable context with parent context.
Click to show internal directories.
Click to hide internal directories.