object Receive
Basic functionality for receiving together with pattern matching.
Receiving is done either through Receive.apply or with Receive.withTimeout. Typical example:
Receive { case Request(from, to, req) if (to-me).nonEmpty => SEND(Request(me, to-me, req)) SEND(Ack(me, from)) case Ack(from, _) => countAcks += 1 }
or with a timeout:
Receive.withTimeout(10.0) { case Request(from, to, req) if (to-me).nonEmpty => SEND(Request(me, to-me, req)) SEND(Ack(me, from)) case Ack(from, _) => countAcks += 1 case Timeout => SEND(Suspect(me, ALL-me)) }
- Alphabetic
- By Inheritance
- Receive
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
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
apply(handler: Function[Event, Unit]): Unit
Receives and handles the next message in the queue, if any.
Receives and handles the next message in the queue, if any.
If the receive queue is empty, the call blocks until a message arrives. When a message is available, it is removed from the queue, and passed to a handler function (can also be a partial function).
Typical example:
Receive { case Request(from, to, req, _) if (to-me).nonEmpty => SEND(Request(me, to-me, req)) SEND(Ack(me, from)) case Ack(from, _, _) => countAcks += 1 }
Another use is to pass an anonymous function as the handler:
Receive { m => println(m) // other code pertaining to m }
- handler
function applied upon receiving a message. It can be a partial function.
- returns
the value returned by the handler
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
withTimeout(timeout: Time)(handler: Function[Event, Unit]): Unit
Receives and handles the next message in the queue, if any, or times out.
Receives and handles the next message in the queue, if any, or times out.
If the receive queue is empty, the call blocks until a message arrives or the call times out, whichever occurs first. If a message is available before the timeout, it is removed from the queue, and passed as argument to a handler function (which can also be a partial function). If the timeout occurs before a message is received, the internal event Timeout is passed instead.
Typical example:
Receive.withTimeout(Time.second) { case Request(from, to, req, _) if (to-me).nonEmpty => SEND(Request(me, to-me, req)) SEND(Ack(me, from)) case Ack(from, _, _) => countAcks += 1 case Timeout => SEND(Suspect(me, neighbors)) }
- timeout
duration after which a Timeout is issued
- handler
function applied upon receiving a message. It can be a partial function.