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

FAQ addition: can you explain joint & join #688

Closed
dgaedcke opened this issue Jul 20, 2017 · 5 comments
Closed

FAQ addition: can you explain joint & join #688

dgaedcke opened this issue Jul 20, 2017 · 5 comments

Comments

@dgaedcke
Copy link

I'd like to understand what they represent and how they work....
I read the reference material but that only show's how to call them...not what they actually do...

@mxcl
Copy link
Owner

mxcl commented Jul 21, 2017

The join resolves the promise.

@dgaedcke
Copy link
Author

Why would I use join instead of just fulfill? Can you show an example?

I've also been looking for docs re: dangers/best practices for saving a pending promise in an instance variable. I have a Social login SDK that opens the Facebook App & asks the user to authenticate, and then returns the results to my AppDelegate external URL handler. It's after that callback from the URL handler that I want to either fulfill or reject my stored promise..

@mxcl
Copy link
Owner

mxcl commented Jul 21, 2017

Joint exists to replace:

let (foo, fulfill, reject) = Promise.pending()
promise.then(fulfill).catch(reject)

// with

let (foo, joint) = Promise.joint()
promise.join(joint)

So for your situation you probably want just .pending().

I'm not improving the docs on Joint as it was an experimental feature we intend to remove due to insufficient value and we have a different way to do it for PMK5.

@dgaedcke
Copy link
Author

sure....if it's going away, I don't need to understand it....
that "pending" pattern makes much more sense to me anyway...
at least the way I've been using it....but your example is quite a bit more concise....
I think (line #2) is saying:
if "promise" succeeds, then "foo" succeeds, else "foo" fails

this teaches me something....so you can pass the completion functions any place another promise is expected.....

@mxcl
Copy link
Owner

mxcl commented Nov 5, 2017

PromiseKit 5 abandons this construct.

@mxcl mxcl closed this as completed Nov 5, 2017
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

No branches or pull requests

2 participants