-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-10182: [C++] Add basic continuation support to Future #8680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
94c0886 to
51b699b
Compare
|
Added a benchmark to measure the cost of creating a Future in Executor::Submit instead of just using Executor::Spawn. Locally: This shows there is significant overhead for small tasks and pools with fewer threads. Follow up: https://issues.apache.org/jira/browse/ARROW-10625 |
pitrou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, really nice.
cpp/src/arrow/util/future_test.cc
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Do we want to use FnOnce in other places at some point? (perhaps open a JIRA?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it should replace std::function in thread_pool.h at least
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ove. Added multi threaded stress test case for AddCallback
91074ab to
9e04cf0
Compare
cpp/src/arrow/util/future.h
Outdated
| /// | ||
| /// The callback should receive the result of the future (const Result<T>&) | ||
| /// For a void or statusy future this should be | ||
| /// (const Result<Future<detail::Empty>::ValueType>& result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... which is? Ideally, the user gets something "simple", such as Status or const Status&.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. They receive const Result<T>& or const Result<detail::Empty>&
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's preferable to keep things as generic as possible, so the empty result is preferable to the plain Status
| void AssertSuccessful(const Future<T>& fut) { | ||
| ASSERT_EQ(fut.state(), FutureState::SUCCESS); | ||
| ASSERT_OK(fut.status()); | ||
| if (IsFutureFinished(fut.state())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is changing the meaning of the tests, as now a pending future will pass this silently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. There should be an else block calling FAIL. I'll add that. The intent of this "if" wrapper is to prevent a pending future from deadlocking the test (which makes it difficult to debug). It absolutely should fail if the future is pending.
|
CI failures are unrelated. Will merge |
westonpace
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adds
Future<T>::Then(OnSuccess, OnFailure)which registers callbacks to be executed on completion of the future and yields a future which wraps the result of those callbacks; if a callback returns:void, Then() returns aFuture<>which completes successully as soon as the callback runs.Status, Then() returns aFuture<>which completes with the returnedStatusas soon as the callback runs.VorResult<V>, Then() returns aFuture<V>which completes with whatever the callback returns.Future<V>, Then() returns aFuture<V>which will be marked complete when the future returned by the callback completes (and will complete with the same result).