class Capsul[T] extends AnyRef
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.
- Alphabetic
- By Inheritance
- Capsul
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new Capsul(init: T, thread: SequentialExecutor)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
access[R](fn: (T) ⇒ R): StagedFuture[R]
Perform a function with the current state
-
def
accessAsync[R](fn: (T) ⇒ Future[R])(implicit ec: ExecutionContext): StagedFuture[R]
Perform an access which returns a Future[R]
-
def
accessStaged[R](fn: (T) ⇒ StagedFuture[R])(implicit ec: ExecutionContext): StagedFuture[R]
Perform an access which returns a StagedFuture[R]
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
current: Future[T]
Return the current state value
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
mutate[R](fn: (Ref[T]) ⇒ R): StagedFuture[R]
Perform a full mutation
-
def
mutateAsync[R](fn: (Ref[T]) ⇒ Future[R])(implicit ec: ExecutionContext): StagedFuture[R]
Perform a mutation which returns a Future[R]
-
def
mutateStaged[R](fn: (Ref[T]) ⇒ StagedFuture[R])(implicit ec: ExecutionContext): StagedFuture[R]
Perform a mutation which returns a StagedFuture[R]
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
sendAccess(fn: Function1[T, _]): Future[Unit]
Send an access operation
-
def
sendAccessAsync[A](fn: (T) ⇒ Future[A]): Future[Unit]
Send an access operation which returns a Future[R]
-
def
sendAccessStaged[A](fn: (T) ⇒ StagedFuture[A])(implicit ec: ExecutionContext): Future[Unit]
Send an access operation which returns a StagedFuture[R]
-
def
sendSet(updated: T): Future[Unit]
Send a set operation
-
def
sendTransform(fn: (T) ⇒ T): Future[Unit]
Send a pure transformation
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
transform(fn: (T) ⇒ T): StagedFuture[T]
Perform a pure transformation
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )