-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Conversation
@@ -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 |
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.
can i add multiple promises together?
Add a and b together then add that together with c?
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.
You can, but you would get back a Promise[((A, B), C)]
.
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 that probably be documented somewhere.
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.
Q: @Theodus how is that different than a join?
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.
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.
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.
join : Iterator[Promise[A]] -> Promise[Array[A]]
add : (Promise[A], Promise[B]) -> Promise[(A, B)]
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 makes sense to update the add
and join
descriptions to make that clear.
@Theodus what do you think of adding to the top level Promises documentation examples to have examples of using the new methods? |
@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. |
@Theodus So the patterns would be on how to accomplish common async joining etc type things with Promises? sounds good. |
Good to merge once the small doc update above is done. Probably needs an update now that explicit partial call was merged. |
This PR expands the promises API. Closes #1691.