Documentation
¶
Overview ¶
Package semaphore provides a bounded resources implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var New = NewSemaphore
New is a func alias for NewSemaphore. The name NewSemaphore is reduncdant but kept for compatibility.
Functions ¶
This section is empty.
Types ¶
type Semaphore ¶
type Semaphore interface {
// Obtain puts one resource into the semaphore,
// returns true if it succeeds;
// otherwise it blocks until the context is cancelled.
// Obtaining from a closed semaphore should return false.
Obtain(context.Context) bool
// Release takes one resource from the semaphore,
// returns true if it succeeds.
// It should never blocks.
Release() bool
// Capacity returns semaphore's max concurrent resources.
Capacity() int
// Count returns semaphore's current used resources.
Count() int
// Close closes the semaphore, stops obtaining resources
// from it by making Obtain() return false ever since.
Close()
// Closed tells if the semaphore is closed.
Closed() bool
}
Semaphore is a bounded resources abstraction. Ref: https://github.com/golang/go/wiki/BoundingResourceUse
func NewSemaphore ¶
NewSemaphore returns an internal semaphore. This is the exported interface for using semaphore.
Click to show internal directories.
Click to hide internal directories.