eengbrec / Scala Enhancements

In-progress enhancements to the Scala standard library, mostly centered around actors.

commit 115: 24c0eb1f167b
parent 97: 26ae498dfea0
branch: actor_state_machine
added interop test that fails to shutdown due to link problem but otherwise works
eengbrec
9 months ago
r115:24c0eb1f167b 75 loc 2.7 KB embed / history / annotate / raw /
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2005-2009, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// $Id: InputChannel.scala 16893 2009-01-13 13:09:22Z cunei $

package scala.actors

/**
 * The <code>InputChannel</code> trait provides a common interface
 * for all channels from which values can be received.
 *
 * @version 0.9.8
 * @author Philipp Haller
 */
trait InputChannel[+Msg] {

  /**
   * Obtain the next available message matching the predicate <code>p</code>
   * @param p the predicate to use to match a message
   * @return the first matching message, or <code>None</code> if no such Message exists
   */
  def nextMessage(p: (Message[Msg]) => Boolean): Option[Message[Msg]]

  /**
   * Receives a message from this <code>InputChannel</code>.
   *
   * @param  f    a partial function with message patterns and actions
   * @return      result of processing the received value
   */
  def receive[R](f: PartialFunction[Msg, R]): R

  /**
   * Receives a message from this <code>InputChannel</code> within
   * a certain time span.
   *
   * @param  msec the time span before timeout
   * @param  f    a partial function with message patterns and actions
   * @return      result of processing the received value
   */
  def receiveWithin[R](msec: Long)(f: PartialFunction[Any, R]): R

  /**
   * Receives a message from this <code>InputChannel</code>.
   * <p>
   * This method never returns. Therefore, the rest of the computation
   * has to be contained in the actions of the partial function.
   *
   * @param  f    a partial function with message patterns and actions
   * @deprecated use react on EventInputChannel instead
   */
  @deprecated def react(f: PartialFunction[Msg, Unit]): Nothing

  /**
   * Receives a message from this <code>InputChannel</code> within
   * a certain time span.
   * <p>
   * This method never returns. Therefore, the rest of the computation
   * has to be contained in the actions of the partial function.
   *
   * @param  msec the time span before timeout
   * @param  f    a partial function with message patterns and actions
   * @deprecated use reactWithin on EventInputChannel instead
   */
  @deprecated def reactWithin(msec: Long)(f: PartialFunction[Any, Unit]): Nothing

  /**
   * Receives the next message from this <code>Channel</code>.
   */
  def ? : Msg
}