Search code examples
scalafuture

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


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

Now is Future(None) (Future.apply(None)) less efficient than Future.successful(None)?


Solution

  • 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.