Documentation ¶
Overview ¶
sync-related utils
Index ¶
- func Async(fn func() error) <-chan error
- func Concurrently(ctx context.Context, concurrency int, task func(ctx context.Context) error, ...) error
- func Concurrently2[T any](ctx context.Context, concurrency int, ...) error
- func LockAndUnlock(mu *sync.Mutex) func()
- func ProducerForSlice[T any](input []T) func(context.Context, chan T) error
- type MutexMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Async ¶
runs an async error-returning task in a goroutine and eventually returns the result in a channel
func Concurrently ¶
func Concurrently( ctx context.Context, concurrency int, task func(ctx context.Context) error, workSubmitter func(taskCtx context.Context), ) error
convenience wrapper around errgroup to run a simple task concurrently, and stop each worker if any of the tasks encounter an error during run
func Concurrently2 ¶
func Concurrently2[T any]( ctx context.Context, concurrency int, consume func(ctx context.Context, task T) error, produce func(taskCtx context.Context, work chan T) error, ) error
convenience wrapper around errgroup to run a simple task concurrently, and stop each worker if any of the tasks encounter an error during run
func LockAndUnlock ¶
helper for reducing lock boilerplate by using "defer LockAndUnlock(mu)()" to queue its unlocking
Types ¶
type MutexMap ¶
type MutexMap struct {
// contains filtered or unexported fields
}
Think of this as an infinite number of named bathroom stalls. Each named stall can only be occupied by one person. When you TryLock(): a) it won't open if it's already occupied. (because it's locked inside) decide to do something else b) it opens and you get in and the stall gets reserved/locked for you. When you get out
you call the unlock callback you obtained from TryLock() to return the stall for use.
func NewMutexMap ¶
func NewMutexMap() *MutexMap