Semaphore

sealed trait 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.

If you need functionality that Semaphore doesnt' provide, use a TSemaphore and define it in a zio.stm.ZSTM transaction.

Companion:
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def available(implicit trace: Trace): UIO[Long]

Returns the number of available permits.

Returns the number of available permits.

def withPermit[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A]

Executes the specified workflow, acquiring a permit immediately before the workflow begins execution and releasing it immediately after the workflow completes execution, whether by success, failure, or interruption.

Executes the specified workflow, acquiring a permit immediately before the workflow begins execution and releasing it immediately after the workflow completes execution, whether by success, failure, or interruption.

def withPermitScoped(implicit trace: Trace): ZIO[Scope, Nothing, Unit]

Returns a scoped workflow that describes acquiring a permit as the acquire action and releasing it as the release action.

Returns a scoped workflow that describes acquiring a permit as the acquire action and releasing it as the release action.

def withPermits[R, E, A](n: Long)(zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A]

Executes the specified workflow, acquiring the specified number of permits immediately before the workflow begins execution and releasing them immediately after the workflow completes execution, whether by success, failure, or interruption.

Executes the specified workflow, acquiring the specified number of permits immediately before the workflow begins execution and releasing them immediately after the workflow completes execution, whether by success, failure, or interruption.

def withPermitsScoped(n: Long)(implicit trace: Trace): ZIO[Scope, Nothing, Unit]

Returns a scoped workflow that describes acquiring the specified number of permits and releasing them when the scope is closed.

Returns a scoped workflow that describes acquiring the specified number of permits and releasing them when the scope is closed.