Returns true
if the var is empty, false
otherwise.
Returns true
if the var is empty, false
otherwise.
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 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
putByCallback for the raw, unsafe version that can work with plain callbacks.
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.
is the value to store
is a callback that will be called when the operation succeeded with a result
a cancelable token that can be used to cancel the computation to avoid memory leaks in race conditions
put for the safe future-enabled version.
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.
a future that might already be completed in case the result is available immediately
readByCallback for the raw, unsafe version that can work with plain callbacks.
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.
is a callback that will be called when the operation succeeded with a result
a cancelable token that can be used to cancel the computation to avoid memory leaks in race conditions
read for the safe future-enabled version.
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.
takeByCallback for the raw, unsafe version that can work with plain callbacks.
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.
is a callback that will be called when the operation succeeded with a result
a cancelable token that can be used to cancel the computation to avoid memory leaks in race conditions
take for the safe future-enabled version.
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.
put for the version that can asynchronously wait for the var to become empty
Tries reading the current value, without modifying the var in any way:
Tries reading the current value, without modifying the var in any way:
Some(a)
None
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.
take for the version that can asynchronously wait for the var to become full
Asynchronous mutable location, that is either empty or contains a value of type
A
.It has these fundamental atomic operations:
true
if it succeeded, or returning immediatelyfalse
in case the var was full and thus the operation failedSome(a)
, or otherwise returningNone
in case the var was empty and thus the operation failedSome(a)
, orNone
if emptyThe
AsyncVar
is appropriate for building synchronization primitives and performing simple inter-thread communications. If it helps, it's similar with aBlockingQueue(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).