package capsul
- See also
- Alphabetic
- By Inheritance
- capsul
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
class
Capsul
[T] extends AnyRef
An encapsulation for thread-safe state.
An encapsulation for thread-safe state.
Methods are named <dispatch><operation><mode>
Dispatch types:
- send: Enqueue an action, returning Future[Unit]. Once the future is resolved, the action has been accepted by the worker, but not necessarily performed.
- (none): Perform an action, returning a StagedFuture[T].
Operations:
- mutate: accepts a function of type
Ref[T] => R
, returnsR
- transform: accepts a function of type
T => T
, returns Unit - set: accepts a new value of type
T
, returns Unit - access: accepts a function of type
T => R
, returnsR
. The function is executed sequentually with other tasks, so it's safe to mutateT
. If you simply want to get the current vaue without blocking other tasks, use current.
Modes:
Modes control when the state will accept more work. Each state will accept up to
bufLen
items immediately, and will run the functions sequentually.For asynchronous modes, subsequent tasks will still be run immediately after the function completes, but the task won't be considered done (for the purposes of accepting more tasks) until the future is resolved.
This means that you must be careful with
mutate
actions or with mutable state objects - you may mutate the state during the execution of the function, but you may not do so asynchronously (e.g. after your future completes)- (empty): Synchronous. The task is completed as soon as it returns.
- async: async (Future). The work returns a Future[T], and the next task may begin immediately. This task continues to occupy a slot in this state's queue until the future completes.
- staged: async (StagedFuture). The work returns a StagedFuture[T], and the next task may begin immediately. This task continues to occupy a slot in this state's queue until the StagedFuture is accepted.
- trait EnqueueableTask extends AnyRef
-
class
Ref
[T] extends AnyRef
A wrapper for getting / setting state
- class RingItem [T >: Null <: AnyRef] extends AnyRef
- class SequentialExecutor extends AnyRef
-
trait
StagedFuture
[T] extends Future[T]
A staged future represents both asynchronous acceptance and asynchronous fulfilment of a piece of work.
A staged future represents both asynchronous acceptance and asynchronous fulfilment of a piece of work.
By explicitly representing asynchronous acceptance, consumers can implement backpressure without resorting to synchronous blocking.
It's conceptually just a
Future[Future[T]]
, where the outer future is resolved once the receiver has accepted the work, and the inner future is resolved once the work is actually complete. For convenience, it also implements Future[T] so you can wait for the final result easily when necessary.The only additional methods on top of Future are:
- trait UnitOfWork [A] extends EnqueueableTask
Value Members
- object Capsul
- object SequentialExecutor
- object StagedFuture
- object UnitOfWork