Merge remote branch 'upstream/master'

This commit is contained in:
David Greco 2010-09-15 17:40:09 +02:00
commit 324a76b8c0
2 changed files with 37 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import se.scalablesolutions.akka.actor.{Actor, ActorRef}
import se.scalablesolutions.akka.actor.Actor._
import se.scalablesolutions.akka.dispatch.CompletableFuture
import se.scalablesolutions.akka.AkkaException
import se.scalablesolutions.akka.util.{ Function, SideEffect }
/**
* Implements Oz-style dataflow (single assignment) variables.
@ -27,9 +28,22 @@ object DataFlow {
*/
def thread(body: => Unit): Unit = spawn(body)
/** Executes the supplied SideEffect in another thread
* JavaAPI
*/
def thread(body: SideEffect): Unit = spawn(body.apply)
/** Executes the supplied function in another thread
*/
def thread[A <: AnyRef, R <: AnyRef](body: A => R) =
actorOf(new ReactiveEventBasedThread(body)).start
/** Executes the supplied Function in another thread
* JavaAPI
*/
def thread[A <: AnyRef, R <: AnyRef](body: Function[A,R]) =
actorOf(new ReactiveEventBasedThread(body.apply)).start
private class ReactiveEventBasedThread[A <: AnyRef, T <: AnyRef](body: A => T)
extends Actor {
def receive = {
@ -91,6 +105,11 @@ object DataFlow {
"Attempt to change data flow variable (from [" + this.value.get + "] to [" + ref() + "])")
}
/** Sets the value of this variable (if unset) with the value of the supplied variable
* JavaAPI
*/
def set(ref: DataFlowVariable[T]) { this << ref }
/** Sets the value of this variable (if unset)
*/
def <<(value: T) {
@ -99,6 +118,16 @@ object DataFlow {
"Attempt to change data flow variable (from [" + this.value.get + "] to [" + value + "])")
}
/** Sets the value of this variable (if unset) with the value of the supplied variable
* JavaAPI
*/
def set(value: T) { this << value }
/** Retrieves the value of variable
* throws a DataFlowVariableException if it times out
*/
def get(): T = this()
/** Retrieves the value of variable
* throws a DataFlowVariableException if it times out
*/

View file

@ -13,4 +13,11 @@ trait Function[T,R] {
*/
trait Procedure[T] {
def apply(param: T): Unit
}
}
/**
* An executable piece of code that takes no parameters and doesn't return any value
*/
trait SideEffect {
def apply: Unit
}