semaphore

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package semaphore provides semaphore implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOpMismatch is returned when you call Release before Acquire,
	// or Release after Acquire failed.
	ErrOpMismatch = errors.New("operation mismatch: Release called without a successful Acquire")
)

Functions

This section is empty.

Types

type Semaphore

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

Semaphore is a semaphore.

func NewSemaphore

func NewSemaphore(limit int) *Semaphore

NewSemaphore creates a new Semaphore.

func (*Semaphore) Acquire

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

Acquire acquires a semaphore, blocks until ctx done.

func (*Semaphore) Release

func (s *Semaphore) Release() error

Release releases a semaphore.

type TokenizedSemaphore

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

TokenizedSemaphore is a kind of semaphore which only allow the same token acquire once until it released.

func NewTokenizedSemaphore

func NewTokenizedSemaphore(limit int) *TokenizedSemaphore

NewTokenizedSemaphore creates a new TokenizedSemaphore.

func (*TokenizedSemaphore) Acquire

func (s *TokenizedSemaphore) Acquire(ctx context.Context, token string) error

Acquire acquires a semaphore with given token.

func (*TokenizedSemaphore) Release

func (s *TokenizedSemaphore) Release(token string) error

Release releases a semaphore with given token.

Jump to

Keyboard shortcuts

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