Documentation ¶
Overview ¶
Package syncf contains common utilities for synchronization.
Index ¶
- Variables
- func AwaitSignal(ctx context.Context, signals ...os.Signal)
- func Failure[V any](ctx context.Context, p Promise[V], err error) error
- func Go(ctx context.Context, fun func(ctx context.Context)) (context.CancelFunc, error)
- func GoSync(ctx context.Context, fun func(ctx context.Context)) context.CancelFunc
- func GoWith(ctx context.Context, contextFunc ContextFunc, fun func(ctx context.Context)) (context.CancelFunc, error)
- func GoroutineID(ctx context.Context) (string, bool)
- func IsContextRelated(err error) bool
- func Success[V any](ctx context.Context, p Promise[V], value V) error
- type Clock
- type ClockFunc
- type ContextFunc
- type Locker
- type Promise
- type RWLocker
- type RWMutex
- type Ref
- type Resolve
- type Val
- type Var
- type WaitGroup
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func AwaitSignal ¶
AwaitSignal blocks until a signal is received. By default, listens to DefaultSignals.
func GoWith ¶
func GoWith(ctx context.Context, contextFunc ContextFunc, fun func(ctx context.Context)) (context.CancelFunc, error)
GoWith starts a goroutine. It uses ContextFunc to spawn a new context.Context and then adds a goroutine ID values to that context. CancelFunc should be used for goroutine interruption via context. Error may be returned in case context spawning failed.
func GoroutineID ¶
GoroutineID extracts goroutine ID (which is set by GoWith) from context.Context.
func IsContextRelated ¶
IsContextRelated checks if this is a "context" package error.
Types ¶
type ContextFunc ¶
ContextFunc creates a child context.Context from a given one.
func Deadline ¶
func Deadline(deadline time.Time) ContextFunc
Deadline returns ContextFunc which uses context.WithDeadline.
func Timeout ¶
func Timeout(timeout time.Duration) ContextFunc
Timeout returns ContextFunc which uses context.WithTimeout.
func (ContextFunc) Stack ¶ added in v0.11.0
func (f ContextFunc) Stack(another ContextFunc) ContextFunc
Stack stacks this ContextFunc with another ContextFunc. The resulting ContextFunc will first call the second one, and then the first one.
type Locker ¶
type Locker interface { // Lock locks something. // It returns a context which should be for errors (via context.Context.Err()) and used for further // execution under the lock. CancelFunc must be called to release the lock (usually inside defer). Lock(ctx context.Context) (context.Context, context.CancelFunc) }
Locker may be locked (interruptibly).
var Unlock Locker = unlock{}
Unlock does nothing.
type Promise ¶
type Promise[V any] interface { // Complete is used to complete this Promise. // It should generally not be called more than once. Complete(ctx context.Context, value V, err error) error }
Promise may be completed. This is synonymous to Promise in Scala.
type RWLocker ¶
type RWLocker interface { Locker // RLock acts the same way as Lock does, but it allows for multiple readers to hold the lock (or a single writer). RLock(ctx context.Context) (context.Context, context.CancelFunc) }
RWLocker supports read-write locks.
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
RWMutex is an interruptible reentrant sync.RWMutex implementation.
type Ref ¶ added in v0.11.0
type Ref[V any] interface { // Get is used to get the actual value. // It should block until the value is available. Get(ctx context.Context) (V, error) }
Ref is a value which may not be available yet. This is synonymous to Future in Scala.
func Async ¶ added in v0.11.0
Async starts an asynchronous calculation and returns a Ref to the result.
type Var ¶ added in v0.11.0
type Var[V any] struct { // Direct makes the Complete pass the result directly to Get without buffering. Direct bool // contains filtered or unexported fields }
Var is a Ref and Promise implementation.