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

Add more promise methods (RFC 35) #2084

Merged
merged 2 commits into from
Aug 2, 2017
Merged

Add more promise methods (RFC 35) #2084

merged 2 commits into from
Aug 2, 2017

Conversation

Theodus
Copy link
Contributor

@Theodus Theodus commented Jul 25, 2017

This PR expands the promises API. Closes #1691.

@Theodus Theodus added the changelog - added Automatically add "Added" CHANGELOG entry on merge label Jul 25, 2017
@@ -159,6 +160,88 @@ actor Promise[A: Any #share]
_attach(consume attach)
promise

fun tag add[B: Any #share = A](p: Promise[B]): Promise[(A, B)] =>
"""
Add two promises into one promise that returns the result of both when
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can i add multiple promises together?

Add a and b together then add that together with c?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can, but you would get back a Promise[((A, B), C)].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that probably be documented somewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: @Theodus how is that different than a join?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join combines multiple promises of the same type and returns their final values in an array where they are in an unknown order. add combines promises that may yield values of different types, but even if they are the same type the promise that each value came from is known based on the order that it appears in the final tuple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join : Iterator[Promise[A]] -> Promise[Array[A]]
 add : (Promise[A], Promise[B]) -> Promise[(A, B)]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to update the add and join descriptions to make that clear.

@SeanTAllen
Copy link
Member

@Theodus what do you think of adding to the top level Promises documentation examples to have examples of using the new methods?

@Theodus
Copy link
Contributor Author

Theodus commented Jul 25, 2017

@SeanTAllen I was intending to add an example in the pony patterns for waiting with the timeout and select methods. I don't think it's necessary to add more examples to the top level documentation since it may become a bit overwhelming for new users.

@SeanTAllen
Copy link
Member

@Theodus So the patterns would be on how to accomplish common async joining etc type things with Promises? sounds good.

@SeanTAllen
Copy link
Member

Good to merge once the small doc update above is done.

Probably needs an update now that explicit partial call was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - added Automatically add "Added" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants