Skip to content

Allow ES6-style Promise construction #154

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

Merged
merged 3 commits into from
Jan 5, 2016

Conversation

andrewimm
Copy link
Contributor

Allows Parse.Promises to be constructed in the ES6 "executor" style, without intervening with old construction.

// Valid:
return new Parse.Promise((resolve, reject) => {
  myAsyncFunction((result) => {
    resolve(result);
  });
});

// Also still valid:
let p = new Parse.Promise();
myAsyncFunction((result) => {
  p.resolve(result);
});
return p;

cc @grantland

@andrewimm
Copy link
Contributor Author

Part of the launch checklist for #136

@andrewimm
Copy link
Contributor Author

Also added the following static constructors from the ES6 spec:

Parse.Promise.resolve(value);
Parse.Promise.resolve(thenable); // Chains the new promise to the end of the old one, essentially a noop
Parse.Promise.reject(error);

@@ -26,11 +26,15 @@ var isPromisesAPlusCompliant = true;
* @constructor
*/
export default class ParsePromise {
constructor() {
constructor(closure) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use executor as param name for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 absolutely. I was calling it "closure" before I read the spec and determined it was deemed an "executor"

@peterdotjs
Copy link
Contributor

LGTM.

peterdotjs added a commit that referenced this pull request Jan 5, 2016
@peterdotjs peterdotjs merged commit 5e5c444 into release-1.7.0 Jan 5, 2016
@andrewimm andrewimm deleted the andrewi.promise_constructor branch January 5, 2016 19:10
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.

3 participants