From 2b250f8e4cb7b10e4a6bcda7447fd53c39b79143 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Fri, 30 Dec 2011 15:54:27 +0100 Subject: [PATCH] Added converters from Executor and ExecutorService to ExecutionContext --- .../scala/akka/dispatch/AbstractDispatcher.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/akka-actor/src/main/scala/akka/dispatch/AbstractDispatcher.scala b/akka-actor/src/main/scala/akka/dispatch/AbstractDispatcher.scala index 873f7d2201..bd730a0b19 100644 --- a/akka-actor/src/main/scala/akka/dispatch/AbstractDispatcher.scala +++ b/akka-actor/src/main/scala/akka/dispatch/AbstractDispatcher.scala @@ -89,6 +89,22 @@ final case class TaskInvocation(eventStream: EventStream, runnable: Runnable, cl object ExecutionContext { implicit def defaultExecutionContext(implicit system: ActorSystem): ExecutionContext = system.dispatcher + + /** + * Creates an ExecutionContext from the given ExecutorService + */ + def fromExecutorService(e: ExecutorService): ExecutionContext = new WrappedExecutorService(e) + + /** + * Creates an ExecutionContext from the given Executor + */ + def fromExecutor(e: ExecutorService): ExecutionContext = new WrappedExecutor(e) + + private class WrappedExecutorService(val executor: ExecutorService) extends ExecutorServiceDelegate with ExecutionContext + + private class WrappedExecutor(val executor: Executor) extends Executor with ExecutionContext { + override final def execute(runnable: Runnable): Unit = executor.execute(runnable) + } } /**