Acquires a single permit.
Acquires a single permit. Alias for acquireN(1)
.
acquireN for a version that can acquire multiple permits
withPermit, the preferred way to acquire and release
Acquires n
permits.
Acquires n
permits.
The returned effect semantically blocks until all requested permits are
available. Note that acquires are satisfied in strict FIFO order, so given
a Semaphore[F]
with 2 permits available, an acquireN(3)
will
always be satisfied before a later call to acquireN(1)
.
number of permits to acquire; must be >= 0
acquire for a version acquires a single permit
withPermit, the preferred way to acquire and release
Returns the number of permits currently available.
Returns the number of permits currently available. Always non-negative.
The protocol is unsafe, the semaphore is used in concurrent settings and thus the value returned isn't stable or reliable. Use with care.
Returns a task that will be complete when the specified number of permits are available.
Returns a task that will be complete when the specified number of permits are available.
The protocol is unsafe because by the time the returned
task completes, some other process might have already
acquired the available permits and thus usage of awaitAvailable
can lead to fragile concurrent logic. Use with care.
Can be useful for termination logic, for example to execute a piece of logic once all available permits have been released.
is the number of permits waited on
Obtains a snapshot of the current count.
Releases a permit, returning it to the pool.
Releases a permit, returning it to the pool.
If there are consumers waiting on permits being available, then the first in the queue will be selected and given a permit immediately.
withPermit, the preferred way to acquire and release
Releases n
permits, potentially unblocking up to n
outstanding acquires.
Releases n
permits, potentially unblocking up to n
outstanding acquires.
number of permits to release - must be >= 0
withPermit, the preferred way to acquire and release
Alias for tryAcquireN(1)
.
Alias for tryAcquireN(1)
.
The protocol is unsafe, because with the "try*" methods the user needs a firm grasp of what race conditions are and how they manifest and usage of such methods can lead to very fragile logic.
withPermit the preferred way to acquire and release
acquire for the version that can wait for acquisition
tryAcquireN for the version that can acquire multiple permits
Alias for tryAcquireN(1)
.
Alias for tryAcquireN(1)
.
The protocol is unsafe, because with the "try*" methods the user needs a firm grasp of what race conditions are and how they manifest and usage of such methods can lead to very fragile logic.
withPermit the preferred way to acquire and release
acquire for the version that can wait for acquisition
tryAcquireN for the version that can acquire multiple permits
Returns a new task, ensuring that the given source acquires an available permit from the semaphore before it is executed.
Returns a new task, ensuring that the given source acquires an available permit from the semaphore before it is executed.
The returned task also takes care of resource handling, releasing its permit after being complete.
is an effect to execute once the permit has been acquired; regardless of its result, the permit is released to the pool afterwards
Returns a new task, ensuring that the given source
acquires n
available permits from the semaphore before
it is executed.
Returns a new task, ensuring that the given source
acquires n
available permits from the semaphore before
it is executed.
The returned task also takes care of resource handling, releasing its permits after being complete.
is the number of permits required for the given function to be executed
is an effect to execute once the permits have been acquired; regardless of its result, the permits are released to the pool afterwards
The
Semaphore
is an asynchronous semaphore implementation that limits the parallelism on task execution.The following example instantiates a semaphore with a maximum parallelism of 10:
Credits
Semaphore
is now implementingcats.effect.Semaphore
, deprecating the old MonixTaskSemaphore
.The changes to the interface and some implementation details are inspired by the implementation in Cats-Effect, which was ported from FS2.