semaphore

package
v0.0.0-...-d996d1d Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package semaphore provives semaphore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Semaphore

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

Semaphore is a semaphore.

func New

func New(name string, n int) *Semaphore

New creates a new semaphore with name and capacity.

func (*Semaphore) Capacity

func (s *Semaphore) Capacity() int

Capacity returns capacity of the semaphore.

func (*Semaphore) Do

func (s *Semaphore) Do(ctx context.Context, f func(ctx context.Context) error) (err error)

Do runs f under semaphore.

func (*Semaphore) Name

func (s *Semaphore) Name() string

Name returns name of the semaphore.

func (*Semaphore) NumRequests

func (s *Semaphore) NumRequests() int

NumRequests returns total number of requests.

func (*Semaphore) NumServs

func (s *Semaphore) NumServs() int

NumServs returns number of currently served.

func (*Semaphore) NumWaits

func (s *Semaphore) NumWaits() int

NumWaits returns number of waiters.

func (*Semaphore) TryAcquire

func (s *Semaphore) TryAcquire(ctx context.Context) (context.Context, func(error), error)

TryAcquire acquires a semaphore if available, or return error. It returns a context for acquired semaphore and func to release it.

func (*Semaphore) WaitAcquire

func (s *Semaphore) WaitAcquire(ctx context.Context) (context.Context, func(error), error)

WaitAcquire acquires a semaphore. It returns a context for acquired semaphore and func to release it.

Jump to

Keyboard shortcuts

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