From 543087df9d355d8ea33ef2f4f44947c25b1d06e9 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 18 Oct 2012 17:31:51 +0200 Subject: [PATCH] =?UTF-8?q?mention=20=E2=80=9Cimport=20context.dispatcher?= =?UTF-8?q?=E2=80=9D=20in=20the=20docs,=20see=20#2638?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rst/scala/code/docs/future/FutureDocSpec.scala | 14 ++++++++++++++ akka-docs/rst/scala/futures.rst | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/akka-docs/rst/scala/code/docs/future/FutureDocSpec.scala b/akka-docs/rst/scala/code/docs/future/FutureDocSpec.scala index b7ea972f63..6e6a3521d1 100644 --- a/akka-docs/rst/scala/code/docs/future/FutureDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/future/FutureDocSpec.scala @@ -394,4 +394,18 @@ class FutureDocSpec extends AkkaSpec { intercept[IllegalStateException] { Await.result(result, 2 second) } } + "demonstrate context.dispatcher" in { + //#context-dispatcher + class A extends Actor { + import context.dispatcher + val f = Future("hello") + def receive = { + //#receive-omitted + case _ ⇒ + //#receive-omitted + } + } + //#context-dispatcher + } + } diff --git a/akka-docs/rst/scala/futures.rst b/akka-docs/rst/scala/futures.rst index 1b4df4154b..0347d93e4b 100644 --- a/akka-docs/rst/scala/futures.rst +++ b/akka-docs/rst/scala/futures.rst @@ -22,6 +22,19 @@ by the ``ExecutionContext`` companion object to wrap ``Executors`` and ``Executo .. includecode:: code/docs/future/FutureDocSpec.scala :include: diy-execution-context +Within Actors +^^^^^^^^^^^^^ + +Each actor is configured to be run on a :class:`MessageDispatcher`, and that +dispatcher doubles as an :class:`ExecutionContext`. If the nature of the Future +calls invoked by the actor matches or is compatible with the activities of that +actor (e.g. all CPU bound and no latency requirements), then it may be easiest +to reuse the dispatcher for running the Futures by importing +``context.dispatcher``. + +.. includecode:: code/docs/future/FutureDocSpec.scala#context-dispatcher + :exclude: receive-omitted + Use With Actors ---------------