sem

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

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 supports to change the max sema amount at runtime.

Semaphore employs golang.org/x/sync/semaphore.Weighted with a maxCapacity.
And tuning the realCapacity by a Acquire and Release in the background.
the realCapacity can not exceeds the maxCapacity.

func NewSem

func NewSem(n uint32) *Semaphore

func (*Semaphore) Acquire

func (s *Semaphore) Acquire()

func (*Semaphore) AcquireWithContext added in v1.1.0

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

func (*Semaphore) Release

func (s *Semaphore) Release()

func (*Semaphore) SetMaxCount

func (s *Semaphore) SetMaxCount(n int64) (done chan struct{})

SetMaxCount set the size of 's' to 'n', this is an async operation and the caller can watch the returned 'done' channel like below if it wants to be notified at the completion:

done := s.SetMaxCount(100)
<-done

Note after receiving the notification, the caller should NOT assume the size of 's' is 'n' unless it knows there are no concurrent calls to 'SetMaxCount'.

Jump to

Keyboard shortcuts

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