ctxsync

package
v0.2300.6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package ctxsync contains some synchronization primitvies that are aware of a context becoming done and can bail on waits in that case.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelableCond

type CancelableCond struct {
	// L is held while observing or changing the condition
	L sync.Locker
	// contains filtered or unexported fields
}

CancelableCond is like sync.Cond, but you can wait with a context and bail when the context is done.

func NewCancelableCond

func NewCancelableCond(l sync.Locker) *CancelableCond

NewCancelableCond returns a new CancelableCond.

func (*CancelableCond) Broadcast

func (c *CancelableCond) Broadcast()

Broadcast wakes all goroutines waiting on c. The caller must hold c.L during the call.

func (*CancelableCond) Wait

func (c *CancelableCond) Wait(ctx context.Context) bool

Wait atomically unlocks c.L and suspends execution of the calling goroutine. After later resuming execution, Wait locks c.L before returning. Returns true if awoken by Broadcast or false if the context is done. Because c.L is not locked when Wait first resumes, the caller typically cannot assume that the condition is true when Wait returns. Instead, the caller should Wait in a loop.

Jump to

Keyboard shortcuts

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