Documentation
¶
Overview ¶
Package syncs provides synchronization primitives util functions.
Index ¶
- func ContextValue(key, value any) context.Context
- func Go(f func() error) error
- func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() error, interrupt func(error))
- func WaitCloseSignals(onClose func(sig os.Signal), sigCh ...chan os.Signal)
- type ErrGroup
- type SafeMap
- type SignalError
- type WaitGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextValue ¶ added in v0.7.2
ContextValue create a new context with given value
func Go ¶
Go is a basic promise implementation: it wraps calls a function in a goroutine and returns a channel which will later return the function's return value.
if panic happen, it will be recovered and return as error
func SignalHandler ¶
func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() error, interrupt func(error))
SignalHandler returns an actor, i.e. an execute and interrupt func, that terminates with SignalError when the process receives one of the provided signals, or the parent context is canceled.
Types ¶
type ErrGroup ¶ added in v0.6.13
ErrGroup is a collection of goroutines working on subtasks that are part of the same overall task.
Refers:
https://github.com/neilotoole/errgroup https://github.com/fatih/semgroup
func NewCtxErrGroup ¶ added in v0.6.13
NewCtxErrGroup instance
func (*ErrGroup) Go ¶ added in v0.7.4
Go add a handler function. if panic occurs, will catch it and return as error
type SafeMap ¶ added in v0.7.4
type SafeMap[K comparable, V any] struct { // contains filtered or unexported fields }
SafeMap is a goroutine-safe map.
func NewSafeMap ¶ added in v0.7.4
func NewSafeMap[K comparable, V any]() *SafeMap[K, V]
NewSafeMap create a new SafeMap instance.
func (*SafeMap[K, V]) Clear ¶ added in v0.7.4
func (m *SafeMap[K, V]) Clear()
Clear do clear all map values.
func (*SafeMap[K, V]) Delete ¶ added in v0.7.4
func (m *SafeMap[K, V]) Delete(key K)
Delete value from map.
type SignalError ¶
SignalError is returned by the signal handler's execute function when it terminates due to a received signal.
func (SignalError) Error ¶
func (e SignalError) Error() string
Error implements the error interface.