Created
August 20, 2018 23:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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