Experimental port to Firebase hosting
This commit is contained in:
52
public/es6-promise@4.2.5/lib/es6-promise/promise/all.js
Normal file
52
public/es6-promise@4.2.5/lib/es6-promise/promise/all.js
Normal file
@ -0,0 +1,52 @@
|
||||
import Enumerator from '../enumerator';
|
||||
|
||||
/**
|
||||
`Promise.all` accepts an array of promises, and returns a new promise which
|
||||
is fulfilled with an array of fulfillment values for the passed promises, or
|
||||
rejected with the reason of the first passed promise to be rejected. It casts all
|
||||
elements of the passed iterable to promises as it runs this algorithm.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
let promise1 = resolve(1);
|
||||
let promise2 = resolve(2);
|
||||
let promise3 = resolve(3);
|
||||
let promises = [ promise1, promise2, promise3 ];
|
||||
|
||||
Promise.all(promises).then(function(array){
|
||||
// The array here would be [ 1, 2, 3 ];
|
||||
});
|
||||
```
|
||||
|
||||
If any of the `promises` given to `all` are rejected, the first promise
|
||||
that is rejected will be given as an argument to the returned promises's
|
||||
rejection handler. For example:
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
let promise1 = resolve(1);
|
||||
let promise2 = reject(new Error("2"));
|
||||
let promise3 = reject(new Error("3"));
|
||||
let promises = [ promise1, promise2, promise3 ];
|
||||
|
||||
Promise.all(promises).then(function(array){
|
||||
// Code here never runs because there are rejected promises!
|
||||
}, function(error) {
|
||||
// error.message === "2"
|
||||
});
|
||||
```
|
||||
|
||||
@method all
|
||||
@static
|
||||
@param {Array} entries array of promises
|
||||
@param {String} label optional string for labeling the promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} promise that is fulfilled when all `promises` have been
|
||||
fulfilled, or rejected if any of them become rejected.
|
||||
@static
|
||||
*/
|
||||
export default function all(entries) {
|
||||
return new Enumerator(this, entries).promise;
|
||||
}
|
84
public/es6-promise@4.2.5/lib/es6-promise/promise/race.js
Normal file
84
public/es6-promise@4.2.5/lib/es6-promise/promise/race.js
Normal file
@ -0,0 +1,84 @@
|
||||
import {
|
||||
isArray
|
||||
} from "../utils";
|
||||
|
||||
/**
|
||||
`Promise.race` returns a new promise which is settled in the same way as the
|
||||
first passed promise to settle.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
let promise1 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
resolve('promise 1');
|
||||
}, 200);
|
||||
});
|
||||
|
||||
let promise2 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
resolve('promise 2');
|
||||
}, 100);
|
||||
});
|
||||
|
||||
Promise.race([promise1, promise2]).then(function(result){
|
||||
// result === 'promise 2' because it was resolved before promise1
|
||||
// was resolved.
|
||||
});
|
||||
```
|
||||
|
||||
`Promise.race` is deterministic in that only the state of the first
|
||||
settled promise matters. For example, even if other promises given to the
|
||||
`promises` array argument are resolved, but the first settled promise has
|
||||
become rejected before the other promises became fulfilled, the returned
|
||||
promise will become rejected:
|
||||
|
||||
```javascript
|
||||
let promise1 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
resolve('promise 1');
|
||||
}, 200);
|
||||
});
|
||||
|
||||
let promise2 = new Promise(function(resolve, reject){
|
||||
setTimeout(function(){
|
||||
reject(new Error('promise 2'));
|
||||
}, 100);
|
||||
});
|
||||
|
||||
Promise.race([promise1, promise2]).then(function(result){
|
||||
// Code here never runs
|
||||
}, function(reason){
|
||||
// reason.message === 'promise 2' because promise 2 became rejected before
|
||||
// promise 1 became fulfilled
|
||||
});
|
||||
```
|
||||
|
||||
An example real-world use case is implementing timeouts:
|
||||
|
||||
```javascript
|
||||
Promise.race([ajax('foo.json'), timeout(5000)])
|
||||
```
|
||||
|
||||
@method race
|
||||
@static
|
||||
@param {Array} promises array of promises to observe
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise which settles in the same way as the first passed
|
||||
promise to settle.
|
||||
*/
|
||||
export default function race(entries) {
|
||||
/*jshint validthis:true */
|
||||
let Constructor = this;
|
||||
|
||||
if (!isArray(entries)) {
|
||||
return new Constructor((_, reject) => reject(new TypeError('You must pass an array to race.')));
|
||||
} else {
|
||||
return new Constructor((resolve, reject) => {
|
||||
let length = entries.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
Constructor.resolve(entries[i]).then(resolve, reject);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
46
public/es6-promise@4.2.5/lib/es6-promise/promise/reject.js
Normal file
46
public/es6-promise@4.2.5/lib/es6-promise/promise/reject.js
Normal file
@ -0,0 +1,46 @@
|
||||
import {
|
||||
noop,
|
||||
reject as _reject
|
||||
} from '../-internal';
|
||||
|
||||
/**
|
||||
`Promise.reject` returns a promise rejected with the passed `reason`.
|
||||
It is shorthand for the following:
|
||||
|
||||
```javascript
|
||||
let promise = new Promise(function(resolve, reject){
|
||||
reject(new Error('WHOOPS'));
|
||||
});
|
||||
|
||||
promise.then(function(value){
|
||||
// Code here doesn't run because the promise is rejected!
|
||||
}, function(reason){
|
||||
// reason.message === 'WHOOPS'
|
||||
});
|
||||
```
|
||||
|
||||
Instead of writing the above, your code now simply becomes the following:
|
||||
|
||||
```javascript
|
||||
let promise = Promise.reject(new Error('WHOOPS'));
|
||||
|
||||
promise.then(function(value){
|
||||
// Code here doesn't run because the promise is rejected!
|
||||
}, function(reason){
|
||||
// reason.message === 'WHOOPS'
|
||||
});
|
||||
```
|
||||
|
||||
@method reject
|
||||
@static
|
||||
@param {Any} reason value that the returned promise will be rejected with.
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise rejected with the given `reason`.
|
||||
*/
|
||||
export default function reject(reason) {
|
||||
/*jshint validthis:true */
|
||||
let Constructor = this;
|
||||
let promise = new Constructor(noop);
|
||||
_reject(promise, reason);
|
||||
return promise;
|
||||
}
|
48
public/es6-promise@4.2.5/lib/es6-promise/promise/resolve.js
Normal file
48
public/es6-promise@4.2.5/lib/es6-promise/promise/resolve.js
Normal file
@ -0,0 +1,48 @@
|
||||
import {
|
||||
noop,
|
||||
resolve as _resolve
|
||||
} from '../-internal';
|
||||
|
||||
/**
|
||||
`Promise.resolve` returns a promise that will become resolved with the
|
||||
passed `value`. It is shorthand for the following:
|
||||
|
||||
```javascript
|
||||
let promise = new Promise(function(resolve, reject){
|
||||
resolve(1);
|
||||
});
|
||||
|
||||
promise.then(function(value){
|
||||
// value === 1
|
||||
});
|
||||
```
|
||||
|
||||
Instead of writing the above, your code now simply becomes the following:
|
||||
|
||||
```javascript
|
||||
let promise = Promise.resolve(1);
|
||||
|
||||
promise.then(function(value){
|
||||
// value === 1
|
||||
});
|
||||
```
|
||||
|
||||
@method resolve
|
||||
@static
|
||||
@param {Any} value value that the returned promise will be resolved with
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise that will become fulfilled with the given
|
||||
`value`
|
||||
*/
|
||||
export default function resolve(object) {
|
||||
/*jshint validthis:true */
|
||||
let Constructor = this;
|
||||
|
||||
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
||||
return object;
|
||||
}
|
||||
|
||||
let promise = new Constructor(noop);
|
||||
_resolve(promise, object);
|
||||
return promise;
|
||||
}
|
Reference in New Issue
Block a user