Packages

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:

  • put which fills the var if empty, or waits (asynchronously) otherwise until the var is empty again (with the putByCallback overload)
  • tryPut which fills the var if empty, returning true if it succeeded, or returning immediately false in case the var was full and thus the operation failed
  • take which empties the var if full, returning the contained value, or waits (asynchronously) otherwise until there is a value to pull (with the takeByCallback overload)
  • tryTake which empties the var if full, returning the contained value immediately as Some(a), or otherwise returning None in case the var was empty and thus the operation failed
  • read which reads the var if full, but without taking it from the interval var, or waits (asynchronously) until there is a value to read
  • tryRead tries reading the var without modifying it in any way; if full then returns Some(a), or None if empty

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).

Source
AsyncVar.scala
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
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  6. def emptyCancelable: Cancelable
    Attributes
    protected
    Definition Classes
    AsyncVar → GenericVar
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def iEmpty(): Boolean

    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
    Definition Classes
    Any
  14. def makeCancelable(f: (Id) ⇒ Unit, id: Id): Cancelable
    Attributes
    protected
    Definition Classes
    AsyncVar → GenericVar
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. def put(a: A): CancelableFuture[Unit]

    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

    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]

    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

    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
    Definition Classes
    AnyRef
  23. def take(): CancelableFuture[A]

    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

    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
    Definition Classes
    AnyRef → Any
  26. def tryPut(a: A): Boolean

    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]

    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]

    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
    Attributes
    protected
    Definition Classes
    GenericVar
  30. final def unsafePut(a: A, await: (Either[Nothing, Unit]) ⇒ Unit): Cancelable
    Attributes
    protected
    Definition Classes
    GenericVar
  31. final def unsafeRead(await: (Either[Nothing, A]) ⇒ Unit): Cancelable
    Attributes
    protected
    Definition Classes
    GenericVar
  32. final def unsafeTake(await: (Either[Nothing, A]) ⇒ Unit): Cancelable
    Attributes
    protected
    Definition Classes
    GenericVar
  33. final def unsafeTryPut(a: A): Boolean
    Attributes
    protected
    Definition Classes
    GenericVar
  34. final def unsafeTryRead(): Option[A]
    Attributes
    protected
    Definition Classes
    GenericVar
  35. final def unsafeTryTake(): Option[A]
    Attributes
    protected
    Definition Classes
    GenericVar
  36. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from GenericVar[A, Cancelable]

Inherited from AnyRef

Inherited from Any

Ungrouped