-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
default.go
33 lines (26 loc) · 947 Bytes
/
default.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package semaphore
import "runtime"
var def = New(runtime.GOMAXPROCS(0))
// Acquire tries to reduce the number of available slots of the default semaphore for 1.
// The operation can be canceled using deadline channel. In this case,
// it returns an appropriate error.
func Acquire(deadline <-chan struct{}) (ReleaseFunc, error) {
return def.Acquire(deadline)
}
// Capacity returns a capacity of the default semaphore.
func Capacity() int {
return def.Capacity()
}
// Occupied returns a current number of occupied slots of the default semaphore.
func Occupied() int {
return def.Occupied()
}
// Release releases the previously occupied slot of the default semaphore.
func Release() error {
return def.Release()
}
// Signal returns a channel to send to it release function only if Acquire is successful.
// In any case, the channel will be closed.
func Signal(deadline <-chan struct{}) <-chan ReleaseFunc {
return def.Signal(deadline)
}