Adding example on how to roll your own ExecutionContext

This commit is contained in:
Viktor Klang 2012-02-20 15:43:17 +01:00
parent 46fb8c72cd
commit 0f685bdaae
4 changed files with 55 additions and 15 deletions

View file

@ -9,12 +9,10 @@ import akka.testkit._
import akka.actor.Actor
import akka.actor.Props
import akka.actor.Status.Failure
import akka.dispatch.Future
import akka.dispatch.Await
import akka.util.Timeout
import akka.util.duration._
import akka.dispatch.Promise
import java.lang.IllegalStateException
import akka.dispatch.{ ExecutionContext, Future, Await, Promise }
object FutureDocSpec {
@ -41,6 +39,22 @@ object FutureDocSpec {
class FutureDocSpec extends AkkaSpec {
import FutureDocSpec._
"demonstrate usage custom ExecutionContext" in {
val yourExecutorServiceGoesHere = java.util.concurrent.Executors.newSingleThreadExecutor()
//#diy-execution-context
import akka.dispatch.{ ExecutionContext, Promise }
implicit val ec = ExecutionContext.fromExecutorService(yourExecutorServiceGoesHere)
// Do stuff with your brand new shiny ExecutionContext
val f = Promise.successful("foo")
// Then shut your ExecutionContext down at some
// appropriate place in your program/application
ec.shutdown()
//#diy-execution-context
}
"demonstrate usage of blocking from actor" in {
val actor = system.actorOf(Props[MyActor])
val msg = "hello"