Skip to content
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

Move result out of Future instead of copying it #177

Closed
wants to merge 1 commit into from

Conversation

jb-gcx
Copy link
Contributor

@jb-gcx jb-gcx commented Jul 10, 2024

I noticed that results are copied out of djinni::Futures instead of moved, probably due to a forgotten std::move.

Example: auto ptr = djinni::Promise<std::unique_ptr<int>>::resolve(nullptr).get();.
Before this it didn't work (called copy constructor of unique_ptr), now it does.

Testing

I wanted to add a test to verify this works and doesn't break with future versions, but there are no dedicated C++ tests yet. I don't have experience with bazel, so I just added an XCTest to do this. I hope that's okay with you.

Example: `auto ptr = djinni::Promise<std::unique_ptr<int>>::resolve(nullptr).get();`
Before this didn't work (called copy constructor of unique_ptr), now it does.
@li-feng-sc
Copy link
Contributor

Thanks for the contribution. I'm going to merge a slightly variant of your version, basically adding an overload for non-const callers:

    T getValueUnsafe() {return std::move(*value);}

the return type is a value type T rather than reference type T&& because I feel a bit uneasy to return references.

@li-feng-sc
Copy link
Contributor

#180

@li-feng-sc li-feng-sc closed this Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants