Class/Object

cats.effect.concurrent

Semaphore

Related Docs: object Semaphore | package concurrent

Permalink

abstract class Semaphore[F[_]] extends AnyRef

A purely functional semaphore.

A semaphore has a non-negative number of permits available. Acquiring a permit decrements the current number of permits and releasing a permit increases the current number of permits. An acquire that occurs when there are no permits available results in semantic blocking until a permit becomes available.

Blocking acquires are cancelable if the semaphore is created with Semaphore.apply (and hence, with a Concurrent[F] instance). Blocking acquires are non-cancelable if the semaphore is created with Semaphore.async (and hence, with an Async[F] instance).

Source
Semaphore.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Semaphore
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Semaphore()

    Permalink

Abstract Value Members

  1. abstract def acquireN(n: Long): F[Unit]

    Permalink

    Acquires n permits.

    Acquires n permits.

    The returned effect semantically blocks until all requested permits are available. Note that acquires are statisfied in strict FIFO order, so given s: Semaphore[F] with 2 permits available, an acquireN(3) will always be satisfied before a later call to acquireN(1).

    n

    number of permits to acquire - must be >= 0

  2. abstract def available: F[Long]

    Permalink

    Returns the number of permits currently available.

    Returns the number of permits currently available. Always non-negative.

    May be out of date the instant after it is retrieved. Use tryAcquire or tryAcquireN if you wish to attempt an acquire, returning immediately if the current count is not high enough to satisfy the request.

  3. abstract def count: F[Long]

    Permalink

    Obtains a snapshot of the current count.

    Obtains a snapshot of the current count. May be negative.

    Like available when permits are available but returns the number of permits callers are waiting for when there are no permits available.

  4. abstract def releaseN(n: Long): F[Unit]

    Permalink

    Releases n permits, potentially unblocking up to n outstanding acquires.

    Releases n permits, potentially unblocking up to n outstanding acquires.

    n

    number of permits to release - must be >= 0

  5. abstract def tryAcquireN(n: Long): F[Boolean]

    Permalink

    Acquires n permits now and returns true, or returns false immediately.

    Acquires n permits now and returns true, or returns false immediately. Error if n < 0.

    n

    number of permits to acquire - must be >= 0

  6. abstract def withPermit[A](t: F[A]): F[A]

    Permalink

    Returns an effect that acquires a permit, runs the supplied effect, and then releases the permit.

Concrete 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: F[Unit]

    Permalink

    Acquires a single permit.

    Acquires a single permit. Alias for acquireN(1).

  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def clone(): AnyRef

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

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

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

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

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  16. def release: F[Unit]

    Permalink

    Releases a single permit.

    Releases a single permit. Alias for releaseN(1).

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  19. def tryAcquire: F[Boolean]

    Permalink

    Alias for tryAcquireN(1).

  20. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped