Packages

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, returns R
  • 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, returns R. The function is executed sequentually with other tasks, so it's safe to mutate T. 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.
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Capsul
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Capsul(init: T, thread: SequentialExecutor)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def access[R](fn: (T) ⇒ R): StagedFuture[R]

    Perform a function with the current state

  5. def accessAsync[R](fn: (T) ⇒ Future[R])(implicit ec: ExecutionContext): StagedFuture[R]

    Perform an access which returns a Future[R]

  6. def accessStaged[R](fn: (T) ⇒ StagedFuture[R])(implicit ec: ExecutionContext): StagedFuture[R]

    Perform an access which returns a StagedFuture[R]

  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def current: Future[T]

    Return the current state value

  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. def mutate[R](fn: (Ref[T]) ⇒ R): StagedFuture[R]

    Perform a full mutation

  17. def mutateAsync[R](fn: (Ref[T]) ⇒ Future[R])(implicit ec: ExecutionContext): StagedFuture[R]

    Perform a mutation which returns a Future[R]

  18. def mutateStaged[R](fn: (Ref[T]) ⇒ StagedFuture[R])(implicit ec: ExecutionContext): StagedFuture[R]

    Perform a mutation which returns a StagedFuture[R]

  19. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. final def notify(): Unit
    Definition Classes
    AnyRef
  21. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  22. def sendAccess(fn: Function1[T, _]): Future[Unit]

    Send an access operation

  23. def sendAccessAsync[A](fn: (T) ⇒ Future[A]): Future[Unit]

    Send an access operation which returns a Future[R]

  24. def sendAccessStaged[A](fn: (T) ⇒ StagedFuture[A])(implicit ec: ExecutionContext): Future[Unit]

    Send an access operation which returns a StagedFuture[R]

  25. def sendSet(updated: T): Future[Unit]

    Send a set operation

  26. def sendTransform(fn: (T) ⇒ T): Future[Unit]

    Send a pure transformation

  27. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  28. def toString(): String
    Definition Classes
    AnyRef → Any
  29. def transform(fn: (T) ⇒ T): StagedFuture[T]

    Perform a pure transformation

  30. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped