final class TaskSemaphore extends Serializable
The TaskSemaphore
is an asynchronous semaphore implementation that
limits the parallelism on task execution.
The following example instantiates a semaphore with a maximum parallelism of 10:
val semaphore = TaskSemaphore(maxParallelism = 10) def makeRequest(r: HttpRequest): Task[HttpResponse] = ??? // For such a task no more than 10 requests // are allowed to be executed in parallel. val task = semaphore.greenLight(makeRequest(???))
- Source
- TaskSemaphore.scala
- Alphabetic
- By Inheritance
- TaskSemaphore
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
val
acquire: Task[Unit]
Triggers a permit acquisition, returning a task that upon evaluation will only complete after a permit has been acquired.
-
def
activeCount: Coeval[Int]
Returns the number of active tasks that are holding on to the available permits.
-
val
awaitAllReleased: Task[Unit]
Returns a task, that upon evaluation will be complete when all the currently acquired permits are released, or in other words when the activeCount is zero.
Returns a task, that upon evaluation will be complete when all the currently acquired permits are released, or in other words when the activeCount is zero.
This also means that we are going to wait for the acquisition and release of all enqueued promises as well.
-
def
greenLight[A](fa: Task[A]): Task[A]
Creates a new task ensuring that the given source acquires an available permit from the semaphore before it is being executed.
Creates a new task ensuring that the given source acquires an available permit from the semaphore before it is being executed.
The returned task also takes care of resource handling, releasing its permit after being complete.
-
val
release: Task[Unit]
Returns a task that upon evaluation will release a permit, returning it to the pool.
Returns a task that upon evaluation will release a permit, returning it to the pool.
If there are consumers waiting on permits being available, then the first in the queue will be selected and given a permit immediately.
This is the API documentation for the Monix library.
Package Overview
monix.execution exposes lower level primitives for dealing with asynchronous execution:
Atomic
types, as alternative tojava.util.concurrent.atomic
monix.eval is for dealing with evaluation of results, thus exposing Task and Coeval.
monix.reactive exposes the
Observable
pattern:Observable
implementationsmonix.types implements type-class shims, to be translated to type-classes provided by libraries such as Cats or Scalaz.
monix.cats is the optional integration with the Cats library, providing translations for the types described in
monix.types
.monix.scalaz is the optional integration with the Scalaz library, providing translations for the types described in
monix.types
.