final class AsyncSemaphore extends Serializable
The AsyncSemaphore
is an asynchronous semaphore implementation that
limits the parallelism on Future
execution.
The following example instantiates a semaphore with a maximum parallelism of 10:
val semaphore = AsyncSemaphore(maxParallelism = 10) def makeRequest(r: HttpRequest): Future[HttpResponse] = ??? // For such a task no more than 10 requests // are allowed to be executed in parallel. val future = semaphore.greenLight(() => makeRequest(???))
- Source
- AsyncSemaphore.scala
- Alphabetic
- By Inheritance
- AsyncSemaphore
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
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(): CancelableFuture[Unit]
Triggers a permit acquisition, returning a future that will complete when a permit gets acquired.
Triggers a permit acquisition, returning a future that will complete when a permit gets acquired.
- Annotations
- @tailrec()
-
def
activeCount: Int
Returns the number of active tasks that are holding on to the available permits.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
awaitAllReleased(): Future[Unit]
Returns a future that will be complete when all the currently acquired permits are released, or in other words when the activeCount is zero.
Returns a future that 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.
- Annotations
- @tailrec()
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
greenLight[A](f: () ⇒ Future[A])(implicit ec: ExecutionContext): Future[A]
Returns a new future, ensuring that the given source acquires an available permit from the semaphore before it is executed.
Returns a new future, ensuring that the given source acquires an available permit from the semaphore before it is executed.
The returned future also takes care of resource handling, releasing its permit after being complete.
- f
is a function returning the
Future
instance we want to evaluate after we get the permit from the semaphore
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
release(): Unit
Releases a permit, returning it to the pool.
Releases 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.
- Annotations
- @tailrec()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
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
.