contextutil

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 2 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultContext = context.TODO()
View Source
var ErrIncorrectNumberOfItems = errors.New("number of items is not even")

Functions

func ExecFunc added in v0.0.62

func ExecFunc(ctx context.Context, fn func()) error

ExecFunc implements context for a function which has no return values and executes that function. if context is cancelled before function returns it will return context error otherwise it will return nil

func ExecFuncWithThreeReturns added in v0.0.62

func ExecFuncWithThreeReturns[T1 any, T2 any](ctx context.Context, fn func() (T1, T2, error)) (T1, T2, error)

ExecFuncWithThreeReturns wraps a function which has three return values given that last one is error and executes that function in a goroutine there by implementing context if context is cancelled before function returns it will return context error otherwise it will return function's return values

func ExecFuncWithTwoReturns added in v0.0.62

func ExecFuncWithTwoReturns[T1 any](ctx context.Context, fn func() (T1, error)) (T1, error)

ExecFuncWithTwoReturns wraps a function which has two return values given that last one is error and executes that function in a goroutine there by implementing context if context is cancelled before function returns it will return context error otherwise it will return function's return values

func ValueOrDefault added in v0.0.48

func ValueOrDefault(value interface{}) context.Context

ValueOrDefault returns default context if given is nil (using interface to avoid static check reporting)

func WithValues

func WithValues(ctx context.Context, keyValue ...ContextArg) (context.Context, error)

WithValues combines multiple key-value into an existing context

Types

type ContextArg added in v0.0.48

type ContextArg string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL