を作成したり、 や のようなメソッドを適用したりするときに、future
それらに ExecutionContext を指定できます。onSuccess
map
例えば、
val f = future {
// code
} executionContext
f.map(someFunction)(executionContext)
f onSuccess {
// code
} executionContext
ただし、将来の for-comprehension を使用する場合、その部分に ExecutionContext を指定するにはどうすればよいyield
ですか?
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
そして、指定されていない場合、どの ExecutionContext がコードを生成して実行しますか?
編集
わかった。回答のおかげで、私は何かを見つけました。暗黙のExecutionContext (のような)
を定義またはインポートしないと、for-comprehension はコンパイルされません。つまり、for-comprehension は暗黙の ExecutionContext を使用します。Implicits.global
では、暗黙の ExecutionContext なしで for-comprehension を使用するにはどうすればよいでしょうか、つまりどのように指定すればよいのでしょうか?