Skip to content

Instantly share code, notes, and snippets.

@jonjack
Created August 20, 2018 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonjack/1b78c0a07ebc96de49bae869800bc8a0 to your computer and use it in GitHub Desktop.
Save jonjack/1b78c0a07ebc96de49bae869800bc8a0 to your computer and use it in GitHub Desktop.
Demo of specifying an explicit Execution Context to a method to override a default implicit one.
object EcTest extends App {
import scala.concurrent.Future
import scala.concurrent.ExecutionContext
import java.util.concurrent.Executors
val default = scala.concurrent.ExecutionContext.Implicits.global
def test(comp: String)(implicit exc: ExecutionContext = default): Future[String] = Future {
println("Using executor: " + Thread.currentThread().getName)
comp
}
test("Use default executor")
val myExecutor = ExecutionContext.fromExecutor(Executors.newSingleThreadExecutor)
test("Use custom executor")(myExecutor)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment