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

前端 未结 2 617
孤街浪徒
孤街浪徒 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

    Future.apply(None) creates asynchronous computation and executes it. It means that extra lambda object is created and extra task is scheduled (however trivial task).

    Future.successful(None) just produces already completed future. It is more efficient.

提交回复
热议问题