syncutil

package
v0.0.0-...-af2531a Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

TODO: move to gokit

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concurrently

func Concurrently(
	ctx context.Context,
	concurrency int,
	task func(ctx context.Context) error,
	workSubmitter func(taskCtx context.Context) 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

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

func (*MutexMap) Lock

func (n *MutexMap) Lock(key string) func()

func (*MutexMap) TryLock

func (n *MutexMap) TryLock(key string) (func(), bool)

returns false if gate already open/reserved returns true if gate was opened for you. you have to use the returned func to release it

Jump to

Keyboard shortcuts

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