Class/Object

zio.stm

TSemaphore

Related Docs: object TSemaphore | package stm

Permalink

final class TSemaphore extends Serializable

A TSemaphore is a semaphore that can be composed transactionally. Because of the extremely high performance of ZIO's implementation of software transactional memory TSemaphore can support both controlling access to some resource on a standalone basis as well as composing with other STM data structures to solve more advanced concurrency problems.

For basic use cases, the most idiomatic way to work with a semaphore is to use the withPermit operator, which acquires a permit before executing some ZIO effect and release the permit immediately afterward. The permit is guaranteed to be released immediately after the effect completes execution, whether by success, failure, or interruption. Attempting to acquire a permit when a sufficient number of permits are not available will semantically block until permits become available without blocking any underlying operating system threads. If you want to acquire more than one permit at a time you can use withPermits, which allows specifying a number of permits to acquire. You can also use withPermitScoped or withPermitsScoped to acquire and release permits within the context of a scoped effect for composing with other resources.

For more advanced concurrency problems you can use the acquire and release operators directly, or their variants acquireN and releaseN, all of which return STM transactions. Thus, they can be composed to form larger STM transactions, for example acquiring permits from two different semaphores transactionally and later releasing them transactionally to safely synchronize on access to two different mutable variables.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. TSemaphore
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def acquire: USTM[Unit]

    Permalink

    Acquires a single permit in transactional context.

  5. def acquireN(n: Long): USTM[Unit]

    Permalink

    Acquires the specified number of permits in a transactional context.

  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def available: USTM[Long]

    Permalink

    Returns the number of available permits in a transactional context.

  8. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. val permits: TRef[Long]

    Permalink
  19. def release: USTM[Unit]

    Permalink

    Releases a single permit in a transactional context.

  20. def releaseN(n: Long): USTM[Unit]

    Permalink

    Releases the specified number of permits in a transactional context

  21. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  22. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  23. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. def withPermit[R, E, A](zio: ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A]

    Permalink

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

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

    Permalink

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

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

    Permalink

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

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

    Permalink

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

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped