Semaphore

final class Semaphore extends Serializable

An asynchronous semaphore, which is a generalization of a mutex. Semaphores have a certain number of permits, which can be held and released concurrently by different parties. Attempts to acquire more permits than available result in the acquiring fiber being suspended until the specified number of permits become available.

Companion:
object
class Object
trait Matchable
class Any

Value members

Concrete methods

The number of permits currently available.

The number of permits currently available.

def withPermit[R, E, A](task: ZIO[R, E, A]): ZIO[R, E, A]

Acquires a permit, executes the action and releases the permit right after.

Acquires a permit, executes the action and releases the permit right after.

def withPermitManaged[R, E]: ZManaged[R, E, Unit]

Acquires a permit in a zio.ZManaged and releases the permit in the finalizer.

Acquires a permit in a zio.ZManaged and releases the permit in the finalizer.

def withPermits[R, E, A](n: Long)(task: ZIO[R, E, A]): ZIO[R, E, A]

Acquires n permits, executes the action and releases the permits right after.

Acquires n permits, executes the action and releases the permits right after.

def withPermitsManaged[R, E](n: Long): ZManaged[R, E, Unit]

Acquires n permits in a zio.ZManaged and releases the permits in the finalizer.

Acquires n permits in a zio.ZManaged and releases the permits in the finalizer.