Class/Object

monix.execution.misc

AsyncSemaphore

Related Docs: object AsyncSemaphore | package misc

Permalink

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(???))
Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AsyncSemaphore
  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(): CancelableFuture[Unit]

    Permalink

    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()
  5. def activeCount: Int

    Permalink

    Returns the number of active tasks that are holding on to the available permits.

  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def awaitAllReleased(): Future[Unit]

    Permalink

    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()
  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 greenLight[A](f: () ⇒ Future[A])(implicit ec: ExecutionContext): Future[A]

    Permalink

    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

  14. def hashCode(): Int

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  19. def release(): Unit

    Permalink

    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()
  20. final def synchronized[T0](arg0: ⇒ T0): T0

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

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

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

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

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

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped