sync: Index | Files

package semaphore

import ""

Package semaphore provides a weighted semaphore implementation.


Package Files


type Weighted Uses

type Weighted struct {
    // contains filtered or unexported fields

Weighted provides a way to bound concurrent access to a resource. The callers can request access with a given weight.

func NewWeighted Uses

func NewWeighted(n int64) *Weighted

NewWeighted creates a new weighted semaphore with the given maximum combined weight for concurrent access.

func (*Weighted) Acquire Uses

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

Acquire acquires the semaphore with a weight of n, blocking only until 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.

func (*Weighted) Release Uses

func (s *Weighted) Release(n int64)

Release releases the semaphore with a weight of n.

func (*Weighted) TryAcquire Uses

func (s *Weighted) TryAcquire(n int64) bool

TryAcquire acquires the semaphore with a weight of n without blocking. On success, returns true. On failure, returns false and leaves the semaphore unchanged.

Package semaphore imports 3 packages (graph) and is imported by 3 packages. Updated 2017-09-27. Refresh now. Tools for package owners.