Is there a Future/Promise equivalent of C++ in D?

前端 未结 1 694
臣服心动
臣服心动 2021-01-25 15:13

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

Sure there is std.parallelism but it\'s doesn\'t have exactly the functionality of the pr

相关标签:
1条回答
  • 2021-01-25 15:57

    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() waits until the future has a valid result and (depending on which template is used) retrieves it. That is exactly what yieldForce does.

    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 "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).

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

    0 讨论(0)
提交回复
热议问题