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 an Acquire and Release in the background. the realCapacity can not exceed the maxCapacity.
func (*Semaphore) AcquireWithContext ¶ added in v1.1.0
AcquireWithContext acquires the semaphore with context
func (*Semaphore) SetMaxCount ¶
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'.
Click to show internal directories.
Click to hide internal directories.