"Future.successful(None)"和"Future.successful(None)"之间有什么区别?和"Future(None)"(将来(无)) [英] What is the difference between "Future.successful(None)" and "Future(None)"

查看:57
本文介绍了"Future.successful(None)"和"Future.successful(None)"之间有什么区别?和"Future(None)"(将来(无))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Future.apply开始异步计算,而Future.successful创建具有指定结果的已经完成的Future.

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

现在Future(None)(Future.apply(None))的效率比Future.successful(None)低吗?

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

推荐答案

Future.apply(None)创建并执行异步计算.这意味着将创建额外的lambda对象并计划额外的任务(但是琐碎的任务).

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)只是产生已经完成的将来.效率更高.

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

这篇关于"Future.successful(None)"和"Future.successful(None)"之间有什么区别?和"Future(None)"(将来(无))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆