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
unsafePut for the raw, unsafe version that can work with plain callbacks.
Tries reading the current value, or blocks (asynchronously)
otherwise, until there is a value available, at which point
the operation resorts to a take
followed by a put
.
Tries reading the current value, or blocks (asynchronously)
otherwise, until there is a value available, at which point
the operation resorts to a take
followed by a put
.
This read
operation is equivalent to:
for (a <- v.take; _ <- v.put(a)) yield a
This operation is not atomic. Being equivalent with a take
followed by a put
, in order to ensure that no race conditions
happen, additional synchronization is necessary.
See AsyncSemaphore for a possible solution.
a future that might already be completed in case the result is available immediately
unsafeRead 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.
unsafeTake 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 (or unsafeTake).
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 (or unsafeTake).
This operation is atomic.
is the value to store
is a callback that, only in case of asynchronous blocking, will get called when the blocking is over and the operation succeeded
true
if the operation succeeded already, with no
blocking necessary, or false
if the operation
is blocked because the var is already full
put for the safe future-enabled version.
Tries reading the current value, or blocks (asynchronously)
otherwise, until there is a value available, at which point
the operation resorts to a take
followed by a put
.
Tries reading the current value, or blocks (asynchronously)
otherwise, until there is a value available, at which point
the operation resorts to a take
followed by a put
.
This read
operation is equivalent to:
for (a <- v.take; _ <- v.put(a)) yield a
This operation is not atomic. Being equivalent with a take
followed by a put
, in order to ensure that no race conditions
happen, additional synchronization is necessary.
See AsyncSemaphore for a possible solution.
is a callback that, only in case of asynchronous blocking, will get called sometime in the future with a value
a value of type A
if the operation succeeded already,
with no blocking necessary, or null
if async blocking
is in progress (in which case the await
callback
gets called with the result)
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.
is a callback that, only in case of asynchronous blocking, will get called sometime in the future with a value
a value of type A
if the operation succeeded already,
with no blocking necessary, or null
if async blocking
is in progress (in which case the await
callback
gets called with the result)
take for the safe future-enabled version.
Asynchronous mutable location, that is either empty or contains a value of type
A
.It has 2 fundamental atomic operations:
The
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.
Inspired by
Control.Concurrent.MVar
from Haskell.