What is the difference between “Future.successful(None)” and “Future(None)”

前端 未结 2 622
孤街浪徒
孤街浪徒 2021-02-05 01:32

Future.apply starts an asynchronous computation whereas Future.successful creates an already completed Future with the specified result.

Now is

2条回答
  •  你的背包
    2021-02-05 02:11

    I don't think that Future(None) gives a big overhead, but still in it's default implementation each call to apply spawns a new task for a ForkJoin thread pool, whereas Future.successful(None) completes immediately. And each call to map or flatMap on the future creates a new task for the poll, which also gives some overhead, so you might want to take a look at scalaz Future/Task implementation which handles such details more carefully.

提交回复
热议问题