The asynchronous case of Func.
An asynchronous concurrent unbounded queue.
A queue where both insertion and removal are asynchronous, based on a maximum queue size.
An async func sandwiched between two sync ones.
An async func sandwiched between two sync ones. Enables efficient composing of sync funcs around async ones.
Abstracts over synchronous and asynchronous functions.
Abstracts over synchronous and asynchronous functions. Instances can be composed efficiently, building new synchronous functionsn if all component functions are synchronous.
A func is always either a SyncFunc
or an AsyncFunc
.
Extra methods on Future[T], with implicit PML conversion.
Extra methods on Future[T], with implicit PML conversion. NOTE: this should be a value type, but that hits a known a bug in the Scala compiler that was only fixed in 2.11.
The synchronous case of Func.
An asynchronous concurrent unbounded queue. Enqueueing completes immediately, while dequeueing returns a Future that is completed once an object can be removed from the queue.
Attribution: base implementation (enqueue/dequeue part) copied from https://groups.google.com/forum/#!topic/scala-user/lyoAdNs3E1o Originally by Viktor Klang.
Implementation notes:
An instance holds either a sequence of enqueued values Seq[T], or a sequence of dequeue() promises waiting to be fulfilled.
Operations are synchronized using AtomicReference. Each modification is attempted using compareAndSet, and if the comparison failed (i.e. another thread won at the race of modifying the AtomicReference) we start the dequeue/enqueue method from scratch.
I replaced the Seq (implicit List) with a Queue to improve performance, since the original code was appending to the end of the List.
the queue element type