D中是否存在与C ++等效的Future / Promise? [英] Is there a Future/Promise equivalent of C++ in D?

查看:72
本文介绍了D中是否存在与C ++等效的Future / Promise?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

D世界中是否存在C ++世界中的未来/承诺?

Does there exist a future/promise equivalent from the C++ world in the D world?

当然有 std.parallelism ,但是它不完全具有promise / future组合的功能(没有等同于获得未来或设置结果或异常,您也不能等待完成。)

Sure there is std.parallelism but it's doesn't have exactly the functionality of the promise/future combination (there is no equivalent to get the future or the set the result or the exception, you can't also wait for completion).

推荐答案

我相信您没有认真研究 std.parallelism ...相当于获取未来(如果您是说 std :: future 的get()方法)是yieldForce(),spinForce()和workForce()。仔细阅读这些内容,您会发现您也可以等待完成...

I believe you did not seriously look at std.parallelism... Equivalent to "get the future" (if by that you mean the std::future's get() method) are yieldForce(), spinForce() and workForce(). Read about these more carefully and you will see that you can wait for completion as well...

std :: future :: get( )等到将来有一个有效的结果,然后(取决于所使用的模板)进行检索

std::future::get() waits until the future has a valid result and (depending on which template is used) retrieves it. That is exactly what yieldForce does.

关于例外...在哪里看到您无法获得例外??
std.parallelism 页:如果任务未启动但是,在当前线程中执行它。完成后,返回其返回值(如果有)。如果正在进行中,请等待条件变量。 如果引发异常,请重新引发该异常

About exceptions... Where did you see you can't get an exception?? From the std.parallelism page: If the Task isn't started yet, execute it in the current thread. If it's done, return its return value, if any. If it's in progress, wait on a condition variable. If it threw an exception, rethrow that exception.

std.parallelism遭受不尝试复制C ++和/的痛苦或Java以及来自这些社区的人们总是希望事情像过去那样(在那儿做到)。

std.parallelism "suffers" from not trying to copy C++ and/or Java and people who come from these communities always expect things to behave as they are used to (been there, done that).

有人纠正了我,但std.parallelism早于std :: future和std :: promise,对吧?

Someone correct me, but std.parallelism pre-dates std::future and std::promise, right?

这篇关于D中是否存在与C ++等效的Future / Promise?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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