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)
?
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)
?
I don't think that
Future(None)
gives a big overhead, but still in it's default implementation each call toapply
spawns a new task for a ForkJoin thread pool, whereasFuture.successful(None)
completes immediately. And each call tomap
orflatMap
on the future creates a new task for the poll, which also gives some overhead, so you might want to take a look atscalaz
Future/Task implementation which handles such details more carefully.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.