Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

future

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)?

like image 574
Amir Karimi Avatar asked Jan 30 '14 20:01

Amir Karimi


People also ask

What does future successful do Scala?

It is used for performing operations concurrently, in a non-blocking manner, and it enables scaling workloads efficiently across shared resources. The Future. successful method constructs an already completed Future with the specified result. The fact that the Future can be completed immediately is more efficient.

What is a future in Scala?

A Future is a placeholder object for a value that may not yet exist. Generally, the value of the Future is supplied concurrently and can subsequently be used. Composing concurrent tasks in this way tends to result in faster, asynchronous, non-blocking parallel code.


1 Answers

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.

like image 50
i.petruk Avatar answered Oct 12 '22 22:10

i.petruk