Added converters from Executor and ExecutorService to ExecutionContext

This commit is contained in:
Viktor Klang 2011-12-30 15:54:27 +01:00
parent b7cf3e9541
commit 2b250f8e4c

View file

@ -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)
}
}
/**