molecule.channel

RIChan

abstract class RIChan[+A] extends IChan[A]

"Result", "reply" or "response" input channel interface.

Result channels are system-level input channels that deliver only a single message followed by the EOS. They obey channel semantics in that they cannot be read concurrently and they deliver messages only once - a result channel that is read a second time will deliver the EOS signal.

The computations associated to a result channel, and hence transformations like map or flatMap, are only fired lazyliy when a process attempts to read the result from the channel. Transformations featuring side-effects can be executed even if no one is interested in the result by calling the fire() method. This method returns a new result channel that consumes the result after the transformations have been applied and then stores it internally in an intermediate buffer such that it can still be consumed later.

In all situations, the continuations or the transformation functions applied to a result channel are carried by default inside the thread that produces the result. To improve reactiveness and/or isolate concurrent computations from each other, it is prefereable to free as soon as possible the thread that produces results and offload the computation of transformations to the thread that consumes the result. The dispatchTo method, if it is called immediately after a future is created, will dipatch any subsequent continuation or transformation to the standard juc.Executor that it is passed as parameter. For example, this could be either a Platform or a UThread, which both inherit from the Executor interface. In the first case, continuations will be carried inside a new user-level thread created by the target platform. In the second case, the continuations will be pinned down to an existing user-level thread.

Note that in case a message is pure, the result of a result channel can be cached for multiple (sequential) reads using the cache() method. Alternatively, for interoperability with Java, a result can also be wrapped inside a standard juc.Future by invoking the future() method on result channels (this method is provided via an implicit conversion to RIChanWithFuture in the companion object).

A

the type of the message returned by the channel

Self Type
RIChan[A]
Source
RChan.scala
Linear Supertypes
IChan[A], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. RIChan
  2. IChan
  3. AnyRef
  4. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new RIChan()

Abstract Value Members

  1. abstract def poison(signal: Signal): Unit

    Poison this channel and any segment it may have buffered.

    Poison this channel and any segment it may have buffered.

    signal

    the poison signal.

    returns

    Unit

    Definition Classes
    IChan
  2. abstract def read(success: (A) ⇒ Unit, failure: (Signal) ⇒ Unit): Unit

    Read a result asynchronously using continuations for success and failure cases.

    Read a result asynchronously using continuations for success and failure cases.

    success

    continuation invoked in case of success.

    failure

    continuation invoked in case of failure.

    returns

    unit

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def and[B](other: RIChan[B])(implicit ma: Message[A], mb: Message[B]): RIChan[(A, B)]

    Return both the result of this channel and the one of another channel.

    Return both the result of this channel and the one of another channel.

    The new channel created succeeds with both successful results or fails as soon as one of the RIChan fails.

    other

    the other result channel.

    returns

    a pair containing the the result of this channel and the other one.

  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def cache()(implicit ma: Message[A]): RIChan[A]

    Cache the message received on the underlying channel such that the same result can be read multiple times (sequentially).

    Cache the message received on the underlying channel such that the same result can be read multiple times (sequentially).

    Important note: Caching messages violates uniqueness of references. Therefore, one must ensure that only "Pure" messages are cached using this mechanism or be careful when poisoning the resulting channel.

    returns

    a result channel that can be read multiple times.

  9. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  10. final def dispatchTo(executor: Executor): RIChan[A]

    Creates a new result channel whose transformations will be executed in the context of another executor.

    Creates a new result channel whose transformations will be executed in the context of another executor. The executor might be a Platform or a user-level thread (UThread), which both implement the juc.Executor interface.

    executor

    the executor that will execute the subsequent transformations.

    returns

    a result channel whose continuations will be invoked in the context of the executor.

  11. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  13. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  14. def fire()(implicit m: Message[A]): RIChan[A]

    Execute all the transformations stacked up on this result channel, and then cache the result into a new result channel.

    Execute all the transformations stacked up on this result channel, and then cache the result into a new result channel. This method ensures that all side-effects performed by transformations applied on this result channel are executed, even if this future is not consumed. Note that it is useless to invoke this method if transformations have no side-effects.

    returns

    a RIChan.

  15. def flatMap[B](f: (A) ⇒ RIChan[B]): RIChan[B]

    Schedule another asynchronous continuation, which is a function of the result of this channel.

    Schedule another asynchronous continuation, which is a function of the result of this channel.

    The thread that executes the function is defined by how this result channel was created.

    f

    the function that creates a new asynchronous computation using the success result of this channel interface.

    returns

    a new channel interface obtained by chaining a new computation after this result is available.

  16. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  17. def get_!(): A

    BLOCK the native thread until a result is available.

    BLOCK the native thread until a result is available.

    All transformations applied before the result channel (or after a FutureRIChan) was was created will be applied in the same native thread than the one that blocks on this result.

    returns

    the result.

  18. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  19. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  20. def map[B](f: (A) ⇒ B): RIChan[B]

    Map a function to the result of this channel interface.

    Map a function to the result of this channel interface.

    The thread that executes the function is defined by how this result channel was created.

    f

    the function applied to the result produced by this channel in case of success.

    returns

    A new channel interface obtained by applying f to the result of this channel interface.

  21. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  22. final def notify(): Unit

    Definition Classes
    AnyRef
  23. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  24. def onComplete(success: (A) ⇒ Unit, failure: (Signal) ⇒ Unit): Unit

    React to a result asynchronously using continuations for success and failure cases.

    React to a result asynchronously using continuations for success and failure cases.

    success

    continuation invoked in case of success.

    failure

    continuation invoked in case of failure.

    returns

    unit

  25. def or[B](other: RIChan[B])(implicit ma: Message[A], mb: Message[B]): RIChan[Either[A, B]]

    Choose the first result between the result of this channel and the one of another channel.

    Choose the first result between the result of this channel and the one of another channel.

    The new result channel created succeeds with the first successful result returned by either this channel or the other channel. It fails only if both channels fail. The other result channel will be automatically poisoned once a result becomes available.

    other

    the other result channel.

    returns

    either the result of this channel or the result of the other one.

  26. def orCatch[B >: A](recover: PartialFunction[Signal, RIChan[B]]): RIChan[B]

    Fallback to an alternative result channel if this channel raises a signal instead of returning a result.

    Fallback to an alternative result channel if this channel raises a signal instead of returning a result.

    recover

    the partial function invoked if a signal is raised.

    returns

    a new result channel.

  27. def read(k: (Seg[A], IChan[A]) ⇒ Unit): Unit

    Read a segment from this channel.

    Read a segment from this channel.

    k

    the continuation taking the last segment read as parameter and the seed on which to read subsequent segments.

    returns

    Unit

    Definition Classes
    RIChanIChan
  28. def readWithin(delay: Long, unit: TimeUnit)(implicit ma: Message[A]): RIChan[Option[A]]

    Read the result of a result channel within the specified timeout.

    Read the result of a result channel within the specified timeout. If the result is no available within the specified timeout, this channel will be automatically poisoned.

    delay

    the time from now to delay execution.

    unit

    the time unit of the delay parameter.

    returns

    some result if the result becomes available before the timeout, else none.

  29. def select[B](other: RIChan[B])(implicit ma: Message[A], mb: Message[B]): RIChan[Either[(A, RIChan[B]), (B, RIChan[A])]]

    Choose the first result between the result of this channel and the one of another channel.

    Choose the first result between the result of this channel and the one of another channel.

    The new result channel created succeeds with the first successful result returned by either this channel or the other channel. It fails only if both channels fail. Whenever one of the result channels succeeds, the other result channel is returned with the result such that one can attempt to retrieve the other result a second time later.

    other

    the other result channel.

    returns

    either the result of this channel or the result of the other one.

  30. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  31. def toString(): String

    Definition Classes
    AnyRef → Any
  32. def tryReadWithin(delay: Long, unit: TimeUnit)(implicit ma: Message[A]): RIChan[Either[RIChan[A], A]]

    Try to read the result of a result channel within the specified timeout.

    Try to read the result of a result channel within the specified timeout. If the result is not available before the specified timeout, a new result channel is returned, which can be used to retrieve the result again later.

    delay

    the time from now to delay execution.

    unit

    the time unit of the delay parameter.

    returns

    Either the result if it becomes available before the timeout, or a new result channel, which can be read a second time later.

  33. final def wait(): Unit

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

    Definition Classes
    AnyRef
    Annotations
    @throws()
  35. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from IChan[A]

Inherited from AnyRef

Inherited from Any