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 fiber blocking until a permit becomes available.
- Source
- Semaphore.scala
- Alphabetic
- By Inheritance
- Semaphore
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new Semaphore()
Abstract Value Members
- abstract def acquireN(n: Long): F[Unit]
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, anacquireN(3)
will always be satisfied before a later call toacquireN(1)
.This method is interruptible, and in case of interruption it will take care of restoring any permits it has acquired. If it does succeed however, managing permits correctly is the user's responsibility. Use
permit
for a safer but less flexible alternative, when you are using Semaphore merely as a lock.- n
number of permits to acquire - must be >= 0
- abstract def available: F[Long]
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
ortryAcquireN
if you wish to attempt an acquire, returning immediately if the current count is not high enough to satisfy the request. - abstract def count: F[Long]
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.
- abstract def mapK[G[_]](f: ~>[F, G])(implicit G: kernel.MonadCancel[G, _]): Semaphore[G]
Modify the context
F
using natural transformationf
. - abstract def permit: kernel.Resource[F, Unit]
Returns a cats.effect.kernel.Resource that acquires a permit, holds it for the lifetime of the resource, then releases the permit.
- abstract def releaseN(n: Long): F[Unit]
Releases
n
permits, potentially unblocking up ton
outstanding acquires.Releases
n
permits, potentially unblocking up ton
outstanding acquires.- n
number of permits to release - must be >= 0
- abstract def tryAcquireN(n: Long): F[Boolean]
Acquires
n
permits now and returnstrue
, or returnsfalse
immediately.Acquires
n
permits now and returnstrue
, or returnsfalse
immediately. Error ifn < 0
.- n
number of permits to acquire - must be >= 0
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def acquire: F[Unit]
Acquires a single permit.
Acquires a single permit. Alias for
acquireN(1)
. - final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def release: F[Unit]
Releases a single permit.
Releases a single permit. Alias for
releaseN(1)
. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def tryAcquire: F[Boolean]
Alias for
tryAcquireN(1)
. - def tryPermit(implicit F: Applicative[F]): kernel.Resource[F, Boolean]
Returns a cats.effect.kernel.Resource that contains a boolean that indicates whether we acquired a permit or not.
Returns a cats.effect.kernel.Resource that contains a boolean that indicates whether we acquired a permit or not. If the permit was acquired then it is guaranteed to be released at the end of the Resource lifetime
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()