@@ -26,11 +26,15 @@ var isPromisesAPlusCompliant = true;
26
26
* @constructor
27
27
*/
28
28
export default class ParsePromise {
29
- constructor ( ) {
29
+ constructor ( executor ) {
30
30
this . _resolved = false ;
31
31
this . _rejected = false ;
32
32
this . _resolvedCallbacks = [ ] ;
33
33
this . _rejectedCallbacks = [ ] ;
34
+
35
+ if ( typeof executor === 'function' ) {
36
+ executor ( this . resolve . bind ( this ) , this . reject . bind ( this ) ) ;
37
+ }
34
38
}
35
39
36
40
/**
@@ -301,6 +305,26 @@ export default class ParsePromise {
301
305
return promise ;
302
306
}
303
307
308
+ /**
309
+ * Returns a new promise that is resolved with a given value.
310
+ * If that value is a thenable Promise (has a .then() prototype
311
+ * method), the new promise will be chained to the end of the
312
+ * value.
313
+ * @method resolve
314
+ * @param value The value to resolve the promise with
315
+ * @static
316
+ * @return {Parse.Promise } the new promise.
317
+ */
318
+ static resolve ( value ) {
319
+ return new ParsePromise ( ( resolve , reject ) => {
320
+ if ( ParsePromise . is ( value ) ) {
321
+ value . then ( resolve , reject ) ;
322
+ } else {
323
+ resolve ( value ) ;
324
+ }
325
+ } ) ;
326
+ }
327
+
304
328
/**
305
329
* Returns a new promise that is rejected with a given error.
306
330
* @method error
@@ -314,6 +338,19 @@ export default class ParsePromise {
314
338
return promise ;
315
339
}
316
340
341
+ /**
342
+ * Returns a new promise that is rejected with a given error.
343
+ * This is an alias for Parse.Promise.error, for compliance with
344
+ * the ES6 implementation.
345
+ * @method reject
346
+ * @param error The error to reject the promise with
347
+ * @static
348
+ * @return {Parse.Promise } the new promise.
349
+ */
350
+ static reject ( ...errors ) {
351
+ return ParsePromise . error . apply ( null , errors ) ;
352
+ }
353
+
317
354
/**
318
355
* Returns a new promise that is fulfilled when all of the input promises
319
356
* are resolved. If any promise in the list fails, then the returned promise
0 commit comments