semaphore

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: Apache-2.0 Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package semaphore provides an implementation of a counting semaphore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Semaphore

type Semaphore chan struct{}

Semaphore is a buffered channel based implementation of a counting semaphore.

func New

func New(permits int) Semaphore

New creates a Semaphore with the specified number of permits.

func (Semaphore) Acquire

func (s Semaphore) Acquire(ctx context.Context) error

Acquire acquires a permit. This call will block until a permit is available or the provided context is completed.

If the provided context is completed, the method will return the cancellation error.

func (Semaphore) Release

func (s Semaphore) Release()

Release releases a permit.

func (Semaphore) TryAcquire

func (s Semaphore) TryAcquire() bool

TryAcquire acquires the semaphore without blocking. Returns true if the semaphore is acquired. Otherwise, returns false and leaves the semaphore unchanged.

Jump to

Keyboard shortcuts

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