Merge pull request #870 from akka/wip-2694-√

#2694 - Fixing DataflowDocSpec examples
This commit is contained in:
Viktor Klang (√) 2012-11-16 07:09:05 -08:00
commit da6b73d5bc
2 changed files with 11 additions and 8 deletions

View file

@ -46,7 +46,7 @@ package object dataflow {
implicit class DataflowPromise[T](val promise: Promise[T]) extends AnyVal {
/**
* Completes the Promise with the speicifed value or throws an exception if already
* Completes the Promise with the specified value or throws an exception if already
* completed. See Promise.success(value) for semantics.
*
* @param value The value which denotes the successful value of the Promise
@ -59,7 +59,7 @@ package object dataflow {
/**
* Completes this Promise with the value of the specified Future when/if it completes.
*
* @param other The Future whose value will be transfered to this Promise upon completion
* @param other The Future whose value will be transferred to this Promise upon completion
* @param ec An ExecutionContext which will be used to execute callbacks registered in this method
* @return A Future representing the result of this operation
*/
@ -75,7 +75,7 @@ package object dataflow {
/**
* Completes this Promise with the value of the specified Promise when/if it completes.
*
* @param other The Promise whose value will be transfered to this Promise upon completion
* @param other The Promise whose value will be transferred to this Promise upon completion
* @param ec An ExecutionContext which will be used to execute callbacks registered in this method
* @return A Future representing the result of this operation
*/

View file

@ -44,21 +44,23 @@ class DataflowDocSpec extends WordSpec with MustMatchers {
}
"demonstrate the use of dataflow variables" in {
def println[T](any: Try[T]): Unit = any.get must be === 20
val result = Promise[Int]()
def println(any: Try[Int]): Unit = result.complete(any)
//#dataflow-variable-a
flow {
val v1, v2 = Promise[Int]()
flow {
// v1 will become the value of v2 + 10 when v2 gets a value
v1 << v2() + 10
v2 << flow { 5 } // As you can see, no blocking!
v1() + v2()
} onComplete println
flow { v2 << 5 } // As you can see, no blocking above!
//#dataflow-variable-a
Await.result(result.future, 10.seconds) must be === 20
}
"demonstrate the difference between for and flow" in {
def println[T](any: Try[T]): Unit = any.get must be === 2
val result = Promise[Int]()
def println(any: Try[Int]): Unit = result.tryComplete(any)
//#for-vs-flow
val f1, f2 = Future { 1 }
@ -68,6 +70,7 @@ class DataflowDocSpec extends WordSpec with MustMatchers {
usingFor onComplete println
usingFlow onComplete println
//#for-vs-flow
Await.result(result.future, 10.seconds) must be === 2
}
}