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.
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
Add SharedFuture #183
Add SharedFuture #183
Changes from 2 commits
ae855ee
74c6a57
edada37
1a4080d
bf60220
987cd72
ce6add1
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
This comment was marked as resolved.
Sorry, something went wrong.
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 this is a difference from Future, where you transform a ready future instead of the result. This was intentional so that the transform function gets to handle exceptions.
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 point regarding exception handling. Changed to handle similarly to Future.
Since this class really is just for convenience, I would opt to keep this chaining to SharedFutures. I think it makes more sense semantically and is cleaner to produce more SharedFutures. Otherwise, this could have just been a simple helper method
cloneFuture(Future<T>& f) -> Future<T>
instead of a full blown class.Finally, regarding
remove_cvref_t
, that's what I used to have, but that is only available in C++20, and we are still configured as c++ 17 for now.This comment was marked as resolved.
Sorry, something went wrong.
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 agree about resources.
But it turns out djnni::Future actually doesn't work with move-only types, anyway. At least that was the case last time I tried; is it different now?
Well you can just call
toFuture()
on the result. it's just a tradeoff of resource vs. convenience.Sure. I added this class because it proves to be challenging to implement a djinni interface that is based on Futures. Specifically, you have a bunch of intermediate results that are Futures, and you need to apply some processing on them when the caller invokes methods returning other Futures. I practice, I always have a bunch of Futures that internally depend on other Futures, in the form of a DAG. This means I needed additional resolved result storage solution for each Future. SharedFuture solved this issue, and I needed all these intermediate results to be SharedFutures, as well. I only ever produce regular Futures again when I finally export them out of the djinni boundary to another language.
This comment was marked as resolved.
Sorry, something went wrong.
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.
So the code is usually something like
So it's just cleaner if
then
produces SharedFuture by default, so I don't have to wrap each result into SharedFuture explicitly 90% of the time.In any case, I updated the code to include both flavors.
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 don't have a strong opinion on this. It kind of makes sense that once someone starts to use SharedFuture they'd want to keep using it.
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 for updating the code. I've got no more complaints, looks great 🎉
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Yeah that's fair. Originally, the lambdas took resolved values instead of the futures, so the overload was kind of needed for SharedFuture. Removed for now.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.
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. The future class was mainly created for bridging with other languages so this is not a super important limitation as we can't have a reference to a C++ object in other languages anyway.
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 call, done.
This comment was marked as resolved.
Sorry, something went wrong.
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 call
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.
@LiFengSC These are translated from the existing cpp tests