Fix compilation errors and minor update to the futures.md

This commit is contained in:
Richard Imaoka 2018-07-29 00:41:09 +09:00
parent 52864ffb28
commit 8f5ea03a6f
2 changed files with 7 additions and 5 deletions

View file

@ -95,8 +95,8 @@ or a `ClassCastException` if not. Handling `Exception`s will be discussed furthe
## Use the pipe pattern ## Use the pipe pattern
Another useful message-transfer pattern is "pipe", which is to send the result of `Future` to another actor, upon completion of the `Future`. Another useful message-transfer pattern is "pipe", which is to send the result of @scala[`Future`]@java[`CompletableFuture`] to another actor, upon completion of the @scala[`Future`]@java[`CompletableFuture`].
The pipe pattern can be used by importing @java[`akka.pattern.PatternsCS.pipe`.]@scala[`akka.pattern.pipe`, and define or import an implicit instance of `ExecutionContext` in the scope. The pipe pattern can be used by importing @java[`akka.pattern.PatternsCS.pipe`.]@scala[`akka.pattern.pipe`, and define or import an implicit instance of `ExecutionContext` in the scope.]
Scala Scala
: @@snip [FutureDocSpec.scala]($code$/scala/docs/future/FutureDocSpec.scala) { #pipe-to-usage } : @@snip [FutureDocSpec.scala]($code$/scala/docs/future/FutureDocSpec.scala) { #pipe-to-usage }

View file

@ -41,8 +41,10 @@ object FutureDocSpec {
import akka.pattern.{ ask, pipe } import akka.pattern.{ ask, pipe }
// implicit ExecutionContext should be in scope // implicit ExecutionContext should be in scope
implicit val ec: ExecutionContext = context.dispatcher implicit val ec: ExecutionContext = context.dispatcher
implicit val timeout: Timeout = 5.seconds
def receive = { def receive = {
case _
val future = target ? "some message" val future = target ? "some message"
future pipeTo sender() // use the pipe pattern future pipeTo sender() // use the pipe pattern
} }