Enable multi_future::get for void multi futures #62
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe the changes
This PR adds a specialization of
multi_future::get
which allows using it onvoid
multi-futures. Without this change, as far as I can tell, it's impossible to catch exceptions thrown by loop bodies in the commonparallelize_loop
case where the body does not return a value. In fact, any such exceptions get silently consumed and the execution of that parallel part of the loop is stopped. That's a pretty significant usability issue, and can be initially difficult to debug.With this PR, the user can at least call
get
on the multi-future to ensure that an exception is forwarded.Testing
We tested this in our code base. Of course it would be easy to add tests for it in the test program as well, but I didn't want to invest that effort before knowing whether the PR would be accepted.
Additional information
Another option would be to change the existing
wait
to useget
. That would reduce the foot-gun potential, but would not be as close to thestd::future
API. On the other hand, I'm not sure if the "just silently ignore exceptions" use case really needs to be supported.