semaphore

package
v0.3.0-nightly.20220727 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Simple

type Simple struct {
	// contains filtered or unexported fields
}

Simple provides a way to bound concurrent access to a resource. It only allows one caller to gain access at a time.

func (*Simple) Acquire

func (s *Simple) Acquire(t Ticket)

Acquire acquires the semaphore, blocking until resources are available. Returns nil if acquire was successful or ctx.Err if the context was cancelled in the meantime.

func (*Simple) Enqueue

func (s *Simple) Enqueue() Ticket

Enqueue reserves the next place in the queue and returns a Ticket used to acquire access to the resource when it's the callers turn. The Ticket has to be supplied to Release before discarding.

func (*Simple) Release

func (s *Simple) Release(t Ticket) error

Release releases the semaphore and notifies the next in line if any. If the ticket was already released the function returns an error. After the ticket is released it should be discarded.

type Ticket

type Ticket struct {
	// contains filtered or unexported fields
}

Ticket reserves a place in the queue and can be used to acquire access to a resource.

Jump to

Keyboard shortcuts

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