Documentation
¶
Index ¶
- Variables
- func GoroutineID() uint64
- func PollUntil[T any](ctx context.Context, timeout, interval time.Duration, cond func() (T, bool)) T
- func RunBounded[T any](ctx context.Context, timeout time.Duration, ...) (value T, timedOut bool, err error)
- type Event
- type GoroutineLocal
- type PanicError
- type ReentrantMutex
- type Semaphore
Constants ¶
This section is empty.
Variables ¶
var ErrExited = errors.New("work exited without returning")
Error of bounded work whose goroutine ended through runtime.Goexit instead of returning or panicking
var ErrOverRelease = errors.New("semaphore released more often than acquired")
Error of a Release that finds every slot of the semaphore already free
Functions ¶
func GoroutineID ¶
func GoroutineID() uint64
Number the runtime gave the calling goroutine, never 0 and never reused while the process lives
func PollUntil ¶
func PollUntil[T any](ctx context.Context, timeout, interval time.Duration, cond func() (T, bool)) T
Calls cond at once and then every interval until it reports done, timeout has passed or ctx ends, giving back the value of its last call; the last wait is cut to the time left
func RunBounded ¶
func RunBounded[T any](ctx context.Context, timeout time.Duration, fn func(ctx context.Context) (T, error)) (value T, timedOut bool, err error)
Runs fn on a goroutine of its own that keeps ctx's values but not its cancellation and waits at most timeout for it; on expiry the goroutine is left to finish unobserved and timedOut is true, when ctx ends first its error comes back, a result ready by then winning over either, a panic in fn comes back as a *PanicError and a runtime.Goexit as ErrExited
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Flag goroutines raise and wait on, lowered again by Clear; the zero Event is lowered and ready to use, and an Event must not be copied after first use
func (*Event) Clear ¶
func (e *Event) Clear()
Lowers the flag so later waits block until the next Set
func (*Event) Done ¶
func (e *Event) Done() <-chan struct{}
Channel closed once the flag is up, for a select arm; after a Clear the next call hands out a fresh channel
func (*Event) WaitContext ¶
Blocks until the flag is up or ctx ends, nil once it is up and the context's error otherwise
type GoroutineLocal ¶
type GoroutineLocal[T any] struct { // contains filtered or unexported fields }
Value slot every goroutine sees on its own, keyed by GoroutineID; slots of finished goroutines are dropped as the slot count grows, and the zero value is empty and ready to use
func (*GoroutineLocal[T]) Delete ¶
func (l *GoroutineLocal[T]) Delete()
Forgets the calling goroutine's value
func (*GoroutineLocal[T]) Get ¶
func (l *GoroutineLocal[T]) Get() (T, bool)
Value the calling goroutine stored, false when it stored none
func (*GoroutineLocal[T]) Set ¶
func (l *GoroutineLocal[T]) Set(v T)
Stores v for the calling goroutine only
type PanicError ¶
Panic of work that ran on a goroutine of its own, carried back to the waiting caller with the stack it panicked on
func (*PanicError) Error ¶
func (e *PanicError) Error() string
The recovered value after "panicked: "
type ReentrantMutex ¶
type ReentrantMutex struct {
// contains filtered or unexported fields
}
Mutex the goroutine holding it may lock again, freed for others once every Lock has had its Unlock; the zero value is unlocked and ready to use, and it must not be copied after first use
func (*ReentrantMutex) Lock ¶
func (m *ReentrantMutex) Lock()
Blocks until the mutex is free or already held by the calling goroutine, then takes one more hold
func (*ReentrantMutex) TryLockFor ¶
func (m *ReentrantMutex) TryLockFor(d time.Duration) bool
Takes one more hold like Lock but gives up once d has passed, reporting whether it got the mutex; a d of zero or less only tries
func (*ReentrantMutex) Unlock ¶
func (m *ReentrantMutex) Unlock()
Drops one hold of the calling goroutine, freeing the mutex when no hold is left; panics when the calling goroutine does not hold it
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Counting semaphore with a fixed number of slots; the zero value has none
func NewSemaphore ¶
Semaphore with n free slots, none when n is not positive
func (*Semaphore) Acquire ¶
Waits for a free slot and takes it, the context's error when ctx ends first
func (*Semaphore) TryAcquire ¶
Takes a slot when one is free, without waiting, reporting whether it got one