sema

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 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 Sema

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

Sema implements semaphore with it can be unlimited by specifying 0

func NewWeighted

func NewWeighted(n int64) *Sema

NewWeighted creates a new weighted semaphore with the given maximum combined weight for concurrent access. When you specify 0, it means unlimited concurrent access.

func (*Sema) Acquire

func (s *Sema) Acquire(ctx context.Context, n int64) error

Acquire acquires the semaphore with a weight of n, blocking until resources are available or ctx is done. On success, returns nil. On failure, returns ctx.Err() and leaves the semaphore unchanged. If ctx is already done, Acquire may still succeed without blocking. If you created semaphore with 0, this method is non blocking.

func (*Sema) Release

func (s *Sema) Release(n int64)

Release releases the semaphore with a weight of n. But if you created semaphore with 0, this method is no effect.

Jump to

Keyboard shortcuts

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