What is execution context in Scala?

后端 未结 1 985
臣服心动
臣服心动 2021-02-13 16:49

I am new to Scala, and was trying to use some parallel constructs(Future in particular).

I found there is an implicit parameter of type ExecutionContex

1条回答
  •  灰色年华
    2021-02-13 17:24

    The basic idea is pretty simple: you have a callback that's going to be executed at some point. On what thread will it be executed? The current one? A new one? One from a pool? That's for the execution context to decide. The default one (ExecutionContext.global) uses threads from a global pool (with a number of threads determined by how many CPU cores you have).

    In other circumstances, you might want to use a different context. For example, Akka actors can use their dispatcher as an execution context.

    0 讨论(0)
提交回复
热议问题