Class/Object

monix.execution

AsyncVar

Related Docs: object AsyncVar | package execution

Permalink

final class AsyncVar[A] extends GenericVar[A, Cancelable]

Asynchronous mutable location, that is either empty or contains a value of type A.

It has these fundamental atomic operations:

The AsyncVar is appropriate for building synchronization primitives and performing simple inter-thread communications. If it helps, it's similar with a BlockingQueue(capacity = 1), except that it doesn't block any threads, all waiting being callback-based.

Given its asynchronous, non-blocking nature, it can be used on top of Javascript as well.

This is inspired by Control.Concurrent.MVar from Haskell, except that the implementation is made to work with plain Scala futures (and is thus impure).

Linear Supertypes
GenericVar[A, Cancelable], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AsyncVar
  2. GenericVar
  3. AnyRef
  4. 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. final def asInstanceOf[T0]: T0

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def emptyCancelable: Cancelable

    Permalink
    Attributes
    protected
    Definition Classes
    AsyncVar → GenericVar
  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. def iEmpty(): Boolean

    Permalink

    Returns true if the var is empty, false otherwise.

    Returns true if the var is empty, false otherwise.

    Annotations
    @UnsafeProtocol() @UnsafeBecauseImpure()
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. def makeCancelable(f: (Id) ⇒ Unit, id: Id): Cancelable

    Permalink
    Attributes
    protected
    Definition Classes
    AsyncVar → GenericVar
  15. final def ne(arg0: AnyRef): Boolean

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

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

    Permalink
    Definition Classes
    AnyRef
  18. def put(a: A): CancelableFuture[Unit]

    Permalink

    Fills the AsyncVar if it is empty, or blocks (asynchronously) if the AsyncVar is full, until the given value is next in line to be consumed on take.

    Fills the AsyncVar if it is empty, or blocks (asynchronously) if the AsyncVar is full, until the given value is next in line to be consumed on take.

    This operation is atomic.

    returns

    a future that will complete when the put operation succeeds in filling the AsyncVar, with the given value being next in line to be consumed; note that this is a cancelable future that can be canceled to avoid memory leaks in race conditions

    Annotations
    @UnsafeBecauseImpure()
    See also

    putByCallback for the raw, unsafe version that can work with plain callbacks.

  19. def putByCallback(a: A, await: Callback[Nothing, Unit]): Cancelable

    Permalink

    Fills the AsyncVar if it is empty, or blocks (asynchronously) if the AsyncVar is full, until the given value is next in line to be consumed on take.

    Fills the AsyncVar if it is empty, or blocks (asynchronously) if the AsyncVar is full, until the given value is next in line to be consumed on take.

    This operation is atomic.

    a

    is the value to store

    await

    is a callback that will be called when the operation succeeded with a result

    returns

    a cancelable token that can be used to cancel the computation to avoid memory leaks in race conditions

    Annotations
    @UnsafeProtocol() @UnsafeBecauseImpure()
    See also

    put for the safe future-enabled version.

  20. def read(): CancelableFuture[A]

    Permalink

    Tries reading the current value, or waits (asynchronously) until there is a value available.

    Tries reading the current value, or waits (asynchronously) until there is a value available.

    This operation is atomic.

    returns

    a future that might already be completed in case the result is available immediately

    Annotations
    @UnsafeBecauseImpure()
    See also

    readByCallback for the raw, unsafe version that can work with plain callbacks.

  21. def readByCallback(await: Callback[Nothing, A]): Cancelable

    Permalink

    Tries reading the current value, or waits (asynchronously) until there is a value available.

    Tries reading the current value, or waits (asynchronously) until there is a value available.

    This operation is atomic.

    await

    is a callback that will be called when the operation succeeded with a result

    returns

    a cancelable token that can be used to cancel the computation to avoid memory leaks in race conditions

    Annotations
    @UnsafeProtocol() @UnsafeBecauseImpure()
    See also

    read for the safe future-enabled version.

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

    Permalink
    Definition Classes
    AnyRef
  23. def take(): CancelableFuture[A]

    Permalink

    Empties the var if full, returning the contained value, or blocks (asynchronously) until a value is available.

    Empties the var if full, returning the contained value, or blocks (asynchronously) until a value is available.

    This operation is atomic.

    Annotations
    @UnsafeBecauseImpure()
    See also

    takeByCallback for the raw, unsafe version that can work with plain callbacks.

  24. def takeByCallback(await: Callback[Nothing, A]): Cancelable

    Permalink

    Empties the var if full, returning the contained value, or blocks (asynchronously) until a value is available.

    Empties the var if full, returning the contained value, or blocks (asynchronously) until a value is available.

    This operation is atomic.

    await

    is a callback that will be called when the operation succeeded with a result

    returns

    a cancelable token that can be used to cancel the computation to avoid memory leaks in race conditions

    Annotations
    @UnsafeProtocol() @UnsafeBecauseImpure()
    See also

    take for the safe future-enabled version.

  25. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  26. def tryPut(a: A): Boolean

    Permalink

    Tries to put a value in the underlying var, returning true if the operation succeeded and thus the var was empty, or false if the var was full and thus the operation failed.

    Tries to put a value in the underlying var, returning true if the operation succeeded and thus the var was empty, or false if the var was full and thus the operation failed.

    Annotations
    @UnsafeProtocol() @UnsafeBecauseImpure()
    See also

    put for the version that can asynchronously wait for the var to become empty

  27. def tryRead(): Option[A]

    Permalink

    Tries reading the current value, without modifying the var in any way:

    Tries reading the current value, without modifying the var in any way:

    • if full, returns Some(a)
    • if empty, returns None
    Annotations
    @UnsafeProtocol() @UnsafeBecauseImpure()
  28. def tryTake(): Option[A]

    Permalink

    Tries to take a value from the underlying var, returning Some(a) if the operation succeeded and thus the var was full, or None if the var was empty and thus the operation failed.

    Tries to take a value from the underlying var, returning Some(a) if the operation succeeded and thus the var was full, or None if the var was empty and thus the operation failed.

    Annotations
    @UnsafeProtocol() @UnsafeBecauseImpure()
    See also

    take for the version that can asynchronously wait for the var to become full

  29. final def unsafeIsEmpty(): Boolean

    Permalink
    Attributes
    protected
    Definition Classes
    GenericVar
  30. final def unsafePut(a: A, await: (Either[Nothing, Unit]) ⇒ Unit): Cancelable

    Permalink
    Attributes
    protected
    Definition Classes
    GenericVar
  31. final def unsafeRead(await: (Either[Nothing, A]) ⇒ Unit): Cancelable

    Permalink
    Attributes
    protected
    Definition Classes
    GenericVar
  32. final def unsafeTake(await: (Either[Nothing, A]) ⇒ Unit): Cancelable

    Permalink
    Attributes
    protected
    Definition Classes
    GenericVar
  33. final def unsafeTryPut(a: A): Boolean

    Permalink
    Attributes
    protected
    Definition Classes
    GenericVar
  34. final def unsafeTryRead(): Option[A]

    Permalink
    Attributes
    protected
    Definition Classes
    GenericVar
  35. final def unsafeTryTake(): Option[A]

    Permalink
    Attributes
    protected
    Definition Classes
    GenericVar
  36. final def wait(): Unit

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

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

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

Inherited from GenericVar[A, Cancelable]

Inherited from AnyRef

Inherited from Any

Ungrouped