When I make a future
, or apply methods like onSuccess
and map
, I can specify ExecutionContext for them.
For example,
val f = future {
// code
} executionContext
f.map(someFunction)(executionContext)
f onSuccess {
// code
} executionContext
However, if I use a for-comprehension of future, how can I specify ExecutionContext for the yield
part?
for {
f <- future1
g <- future2
} yield {
// code to be executed after future1 onSuccess and future2 onSuccess
// What ExecutionContext runs this code?
} // (executionContext) here does not work
And, what ExecutionContext runs the code in yield if not specified?
EDIT
OK. Thanks to answers, I found something.
If I don't define or import implicit ExecutionContext (like Implicits.global
),
the for-comprehension does not compile. That means, for-comprehension uses implicit ExecutionContext.
Then, how can I use for-comprehension without implicit ExecutionContext, i.e. how to specify?
for
comprehensions won't compile if you don't have animplicit
specified. – Alginateambiguous implicit values
. I can block each time I define or import implicit vals or defs & for-comprehension, but is there another way? – Covenanteefor
-comprehension with multiple generators (in which case flavian's answer works) or multiple consequentfor
-comprehensions? – Alginate