mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 09:56:46 +00:00
Fix.
This commit is contained in:
parent
596a6da241
commit
c1a589c5b6
7078 changed files with 1882834 additions and 319 deletions
337
node_modules/rsvp/CHANGELOG.md
generated
vendored
Normal file
337
node_modules/rsvp/CHANGELOG.md
generated
vendored
Normal file
|
@ -0,0 +1,337 @@
|
|||
# Master
|
||||
|
||||
# 4.8.5
|
||||
|
||||
* remove try/catch performance hacks, modern runtimes no longer require these tricks
|
||||
* internal tooling improvements
|
||||
|
||||
# 4.8.2
|
||||
|
||||
* restore cast for 4.x
|
||||
|
||||
# 4.8.1
|
||||
|
||||
* Confuse Webpack (make is easier to pack this module)
|
||||
|
||||
# 4.8.0
|
||||
|
||||
* reject promise when non-array promise is passed to RSVP.filter
|
||||
* fix issue with registering event callbacks
|
||||
* remove publishing to S3 and rely on `npm` and `jsdelivr.com` instead
|
||||
* general cleanup
|
||||
|
||||
# 4.7.0
|
||||
|
||||
* Release the same code as 4.0.2 but as 4.7.0 (fixes issues with `npm outdated`, `yarn update-interactive`, etc caused by accidental publishing of 4.6.1).
|
||||
|
||||
# 4.0.2
|
||||
|
||||
* Fix issue which occurs when you have a `.finally` after a promise has rejected with no rejection value.
|
||||
|
||||
# 4.0.1
|
||||
|
||||
* Fix bug in `RSVP.filter` where it would only respect explicitly `true` values (unlike `[].filter` which allows truthy values).
|
||||
|
||||
# 4.0.0
|
||||
|
||||
* remove es3 fallbacks
|
||||
* make map/filter eager
|
||||
|
||||
# 3.5.0
|
||||
|
||||
* expose RSVP.asap for access to the micro-task polyfil
|
||||
|
||||
# 3.4.0
|
||||
|
||||
* [BUGFIX] Fix memory leak [#446]
|
||||
* Mirror Node's LTS policy
|
||||
* add dist/rsvp.es.js (bundle as a single ES module file)
|
||||
* fix typo in readme
|
||||
|
||||
# 3.3.3
|
||||
|
||||
* [BUGFIX] Fix asap for Titanium \w webpack usage.
|
||||
|
||||
# 3.3.2
|
||||
|
||||
* [BUGFIX] fix invalid ES6
|
||||
|
||||
# 3.3.1
|
||||
|
||||
* [BUGFIX] for compat, ensure both default export and property export exist. This will likely go away in 4.0.0, and was the result of rollup producing proper output with `__esModule: true` brand
|
||||
|
||||
# 3.3.0
|
||||
|
||||
* improve build, switch to broccoli-rollup (among other things)
|
||||
* RSVP.filter() now itself accepts a Promise.all as input
|
||||
* compress and mangle prod build output
|
||||
* [REVERT] reject instead of throwing, spec violation.
|
||||
|
||||
# 3.2.1
|
||||
|
||||
* reject instead of throwing
|
||||
|
||||
# 3.2.0
|
||||
|
||||
* add tamper protection - then / resolve tampering should avoid fast-paths the rely on those being predictable
|
||||
* improve performance of Enumerator operating on non-promise objects
|
||||
* Ensure the promise constructor continues to get inlined.
|
||||
|
||||
# 3.1.0
|
||||
|
||||
* `RSVP.on('error', function(reason, label) { ... }` now also provides the
|
||||
rejected promises label.
|
||||
|
||||
# 3.0.21
|
||||
|
||||
* actually don't publish built tests to npm
|
||||
|
||||
# 3.0.20
|
||||
|
||||
* correctly publish bower & npm
|
||||
|
||||
# 3.0.19
|
||||
|
||||
* don't publish built tests to npm
|
||||
|
||||
# 3.0.18
|
||||
|
||||
* issue with phantomjs 2.0 on travis. I have lost patience..
|
||||
* test on iojs and node 0.12
|
||||
* bump ember-cli
|
||||
* Support objects not inheriting from Object.prototype in RSVP.hash()
|
||||
|
||||
# 3.0.17
|
||||
|
||||
* Added browser field to fix browserification
|
||||
* Fix stripping source map
|
||||
* Fix duplicate imports
|
||||
* Remove unused loader.js dependency
|
||||
* Add the ember-cli dependency checker
|
||||
* Remove the duplicate build script
|
||||
* Remove the static middleware
|
||||
* add npm run build:production
|
||||
* browserify extern not needed
|
||||
* also add lib for those es6 peeps
|
||||
* enusre only dist is included in publishes
|
||||
* strip source maps for now.
|
||||
* copy correct tree into test
|
||||
* prefer start to server
|
||||
* use git-repo-version
|
||||
* ah, prod builds used rename correctly.
|
||||
* remove rename, prefer mv for this scenario
|
||||
* prepend license
|
||||
* Revert "node 0.10.x doesn’t like this. Its not really needed just run `npm run test` or `npm run test:ci`"
|
||||
* node 0.10.x doesn’t like this. Its not really needed just run `npm run test` or `npm run test:ci`
|
||||
* move stuff around + bump to broccoli-stew 0.0.3
|
||||
* bump broccoli-stew which now supports globs
|
||||
* Problem with path for vertx.js.
|
||||
|
||||
# 3.0.16
|
||||
|
||||
* use more supported version of export default
|
||||
* more broccoli fun
|
||||
* remove accidentally imported map file
|
||||
* test non-minified (we can add a flag to test minified next)
|
||||
* [BUGFIX release] Replace closure compiler
|
||||
|
||||
# 3.0.15
|
||||
|
||||
* Added Node 0.11 to travis ci test runner
|
||||
* Replaced deprecated process.nextTick with setImmediate
|
||||
* Ember test and npm run test:node passing
|
||||
* (origin/upgrade-tooling) upgrade tooling
|
||||
* Fix onerror test
|
||||
* [fixes #322] don't inform instrumentation of errors until the current turn is complete.
|
||||
* Follow thenable state not own state
|
||||
* Correct minor spelling error in defer doc example
|
||||
* Set [[AlreadyResolved]] as soon as resolve is called
|
||||
* Finally should correctly trigger on('error')
|
||||
* [fixes #294] finally work correctly with on(‘error’)
|
||||
* Use git-repo-version to calculate build signature
|
||||
* yay the new transpiler supports this now!!!
|
||||
* Use the latest version of the transpiler
|
||||
* add subclassing tests to finally
|
||||
* extern event emitter stuff
|
||||
* [fixes #309] some more externs
|
||||
* ensure those select few using node with minified JS don't have an issue
|
||||
* [fixes #302] use @calvinmetcalf’s promises-aplus-tests-phantom
|
||||
|
||||
# 3.0.14
|
||||
|
||||
* Instrumentation with stack is now opt-in
|
||||
* improve cost of instrumentation by up to 15x in chrome
|
||||
* reduce AST size
|
||||
* last vertex related touch-ups.
|
||||
* Add vert.x compatibility.
|
||||
* [fixes #296] for define.amd and module.exports to no minify
|
||||
* [fixes #292] ensure the deferred's api doesn't break when minified
|
||||
* ignore some files for npm
|
||||
* Add 'finally' to readme
|
||||
* Use browserify assert instead of vendoring one
|
||||
* Use mocha and json3 from npm, not bower
|
||||
* Remove unused json2 file
|
||||
* upgrade build tooling
|
||||
* improve performance of instrumentation (also add seperate flag to include "stack" with instrumentation as it is unfortunately slow)
|
||||
* ensure minified RSVP.defer() maintains known external API [#293](https://github.com/tildeio/rsvp.js/pull/293)
|
||||
* add `finally` to the readme
|
||||
* improve usage of browserify for promise/a+ tests
|
||||
* add wasteful files to gitignore
|
||||
* add [vert.x](http://vertx.io/) compatibility
|
||||
|
||||
# 3.0.13
|
||||
|
||||
* [Bugfix] fix `RSVP.hash` `RSVP.hashSettled` in runtimes < es5 by fixing a broken `Object.create` polyfil [#286](https://github.com/tildeio/rsvp.js/pull/286)
|
||||
* [Enhancement] cleanup & improve test related build tooling [#288](https://github.com/tildeio/rsvp.js/pull/288)
|
||||
|
||||
# 3.0.12
|
||||
|
||||
* [Bugfix] fix regression in denodeify that broke foreign thenables as arguments to denodeifed functions [#281](https://github.com/tildeio/rsvp.js/pull/281)
|
||||
|
||||
# 3.0.11
|
||||
|
||||
* [Bugfix] some onerror scenarios did not result in error notifications [4dcf](https://github.com/tildeio/rsvp.js/commit/4dcfa92bab6f5fc9e97ca3abfb71025a08984e7e)
|
||||
* [Bugfix] for more correctness internal optimization should only occure
|
||||
if constructors equal, not just if instanceof check passes [96b5ec](https://github.com/tildeio/rsvp.js/commit/96b5ec201b2ddafc70cd5c836bc341a46081ae23)
|
||||
* fancy new s3 publishing thanks to @rondale-sc
|
||||
|
||||
# 3.0.10
|
||||
|
||||
* faster denodeify
|
||||
* rework tooling (Broccoli, testem, no grunt)
|
||||
* utilize bundle format for super small UMD builds
|
||||
|
||||
# 3.0.9
|
||||
* [Bugfix] no longer include promise-aplus tests as a production
|
||||
dependency
|
||||
* [Enhancement] fast then path for both rejection/fulfilment [0d252](https://github.com/tildeio/rsvp.js/commit/0d252ed4831eabb82991584e2e3eaae2a3a2ba42)
|
||||
* [Enhancement] short-cut for faster then chaining in specific scenarios
|
||||
[#256](https://github.com/tildeio/rsvp.js/pull/256)
|
||||
|
||||
# 3.0.8
|
||||
* [Bugfix] custom onerror handler, for potentially unhandled errors
|
||||
would report unhandled errors in some incorrect scenarios.
|
||||
[#255](https://github.com/tildeio/rsvp.js/pull/255)
|
||||
|
||||
# 3.0.7
|
||||
|
||||
* improve tests in some older es5+ browsers
|
||||
* [Bugfix] denodeify should not use console for deprecation warning unless console is defined
|
||||
* [Enhancement] instrumentation should emit out-of-band. This should improve ember-extension performance
|
||||
* [Bugfix] race should not be susceptible to zalgo
|
||||
* [Perf] PromiseEnumerator increase performance of all enumerable methods all/allSettled/hash/hasSettled -> https://gist.github.com/stefanpenner/26465d5848f2924e2aca
|
||||
* [Docfix] Fix small documentation inconsistency
|
||||
* [Perf] an internal promise shouldn't bother validating `this` and `resolver`
|
||||
* [Perf] flatten asap’s QUEUE structure
|
||||
* [Perf] Reduce Constructor AST size.
|
||||
* [Perf] some versions of v8, think keep marking these functions to be optimized. This hints to them not to be.
|
||||
* [Perf] accidental resolve step, that merely needed to be a fulfill
|
||||
* [Perf/Enhancement] simplify publishing
|
||||
* [Spec ADdition]add spec test “Ensure `then` is always called with a clean stack.” ensure RSVP passes future a+ spec
|
||||
* [Bugfix] web worker support
|
||||
* [Docfix] Add a param name to make yuidoc happy
|
||||
* [Enhancement] simplify async vs sync pub/sub code-paths
|
||||
* [Bugfix] Passed the label through to the Promise object, as expected
|
||||
* [Docfix] missing Parentheses on promise example in documentation
|
||||
* [License] Add Stefan Penner to license
|
||||
* [Docfix] document `var promises` in filter.js
|
||||
|
||||
# 3.0.3 -> 3.0.6 (missing changelog)
|
||||
|
||||
* Changes to RSVP.denodeify: Behaviour for multiple success callback parameters
|
||||
has been improved and the denodefied function now inherits from the original
|
||||
node function.
|
||||
|
||||
# 3.0.2
|
||||
|
||||
* [Spec compliance] Promise.all and Promise.race should reject, not throw on invalid input
|
||||
* Add RSVP.allSettled
|
||||
|
||||
# 3.0.1
|
||||
|
||||
* Optimization: promises with noop resolvers now don't bother try to handle them.
|
||||
* [perf] skip costly resolver invocation if it is known not to be needed.
|
||||
* improve promise inspector interopt
|
||||
|
||||
# 3.0.0
|
||||
|
||||
* align with the promise spec
|
||||
https://github.com/domenic/promises-unwrapping
|
||||
* idiomatic es6 usage
|
||||
* RSVP.all: now casts rather then resolves, and doesn't touch the
|
||||
"then"
|
||||
* RSVP.hash: now casts rather then resolves, and doesn't touch the
|
||||
"then"
|
||||
* MutationObserver: prefer text mutation, this fixes interop with
|
||||
MutationObserver polyfils
|
||||
* Removing asap unload listener. Allows back/forward page cache, chrome
|
||||
bug is old. Fixes #168
|
||||
* add grunt docs task
|
||||
* document: Promise.cast
|
||||
* document: Promise.resolve/Promise.reject
|
||||
* document: Promise.race
|
||||
* document: Promise.all
|
||||
* document: Promise.hash
|
||||
* document: RSVP.denodeify
|
||||
* document: RSVP.EventTarget
|
||||
* document: RSVP.rethrow
|
||||
* document: RSVP.defer
|
||||
* Document: RSVP.on('error'
|
||||
* Add Instrumentation hooks for tooling
|
||||
* Significant internal cleanup and performance improvements
|
||||
* require Promise constructor to be new'd (aligned with es6 spec)
|
||||
* Prefer tasks + config inline within project
|
||||
* Add Promise.finally
|
||||
* Add Promise.cast
|
||||
* Add Promise.resolve
|
||||
* Add Promise.reject
|
||||
* Add Promise.all
|
||||
* Add Promise.race
|
||||
* Add RSVP.map
|
||||
* Support promise inheritance
|
||||
* optimize onerror and reduce promise creation cost by 20x
|
||||
* promise/a+ 2.0.3 compliant
|
||||
* RSVP.async to schedule callbacks on internal queue
|
||||
* Optimization: only enforce a single nextTick for each queue flush.
|
||||
|
||||
# 2.0.4
|
||||
|
||||
* Fix npm package
|
||||
|
||||
# 2.0.3
|
||||
|
||||
* Fix useSetTimeout bug
|
||||
|
||||
# 2.0.2
|
||||
|
||||
* Adding RSVP#rethrow
|
||||
* add pre-built AMD link to README
|
||||
* adding promise#fail
|
||||
|
||||
# 2.0.1
|
||||
* misc IE fixes, including IE array detection
|
||||
* upload passing builds to s3
|
||||
* async: use three args for addEventListener
|
||||
* satisfy both 1.0 and 1.1 specs
|
||||
* Run reduce tests only in node
|
||||
* RSVP.resolve now simply uses the internal resolution procedure
|
||||
* prevent multiple promise resolutions
|
||||
* simplify thenable handling
|
||||
* pre-allocate the deferred's shape
|
||||
* Moved from Rake-based builds to Grunt
|
||||
* Fix Promise subclassing bug
|
||||
* Add RSVP.configure('onerror')
|
||||
* Throw exception when RSVP.all is called without an array
|
||||
* refactor RSVP.all to just use a promise directly
|
||||
* Make `RSVP.denodeify` pass along `thisArg`
|
||||
* add RSVP.reject
|
||||
* Reject promise if resolver function throws an exception
|
||||
* add travis build-status
|
||||
* correctly test and fix self fulfillment
|
||||
* remove promise coercion.
|
||||
* Fix infinite recursion with deep self fulfilling promises
|
||||
* doc fixes
|
||||
|
||||
# 2.0.0
|
||||
|
||||
* No changelog beyond this point. Here be dragons.
|
19
node_modules/rsvp/LICENSE
generated
vendored
Normal file
19
node_modules/rsvp/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
371
node_modules/rsvp/README.md
generated
vendored
Normal file
371
node_modules/rsvp/README.md
generated
vendored
Normal file
|
@ -0,0 +1,371 @@
|
|||
# RSVP.js [](http://travis-ci.org/tildeio/rsvp.js) [](http://inch-ci.org/github/tildeio/rsvp.js)
|
||||
RSVP.js provides simple tools for organizing asynchronous code.
|
||||
|
||||
Specifically, it is a tiny implementation of Promises/A+.
|
||||
|
||||
It works in node and the browser (IE9+, all the popular evergreen ones).
|
||||
|
||||
## downloads
|
||||
|
||||
- rsvp ([latest](https://cdn.jsdelivr.net/npm/rsvp/dist/rsvp.js) | [4.x](https://cdn.jsdelivr.net/npm/rsvp@4/dist/rsvp.js))
|
||||
- rsvp minified ([latest](https://cdn.jsdelivr.net/npm/rsvp/dist/rsvp.min.js) | [4.x](https://cdn.jsdelivr.net/npm/rsvp@4/dist/rsvp.min.js))
|
||||
|
||||
## CDN
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/rsvp@4/dist/rsvp.min.js"></script>
|
||||
```
|
||||
|
||||
## Promises
|
||||
|
||||
Although RSVP is ES6 compliant, it does bring along some extra toys. If you
|
||||
would prefer a strict ES6 subset, I would suggest checking out our sibling
|
||||
project https://github.com/stefanpenner/es6-promise, It is RSVP but stripped
|
||||
down to the ES6 spec features.
|
||||
|
||||
## Node
|
||||
|
||||
```sh
|
||||
yarn add --save rsvp
|
||||
# or ...
|
||||
npm install --save rsvp
|
||||
```
|
||||
|
||||
`RSVP.Promise` is an implementation of
|
||||
[Promises/A+](http://promises-aplus.github.com/promises-spec/) that passes the
|
||||
[test suite](https://github.com/promises-aplus/promises-tests).
|
||||
|
||||
It delivers all promises asynchronously, even if the value is already
|
||||
available, to help you write consistent code that doesn't change if the
|
||||
underlying data provider changes from synchronous to asynchronous.
|
||||
|
||||
It is compatible with [TaskJS](https://github.com/mozilla/task.js), a library
|
||||
by Dave Herman of Mozilla that uses ES6 generators to allow you to write
|
||||
synchronous code with promises. It currently works in Firefox, and will work in
|
||||
any browser that adds support for ES6 generators. See the section below on
|
||||
TaskJS for more information.
|
||||
|
||||
### Basic Usage
|
||||
|
||||
```javascript
|
||||
var RSVP = require('rsvp');
|
||||
|
||||
var promise = new RSVP.Promise(function(resolve, reject) {
|
||||
// succeed
|
||||
resolve(value);
|
||||
// or reject
|
||||
reject(error);
|
||||
});
|
||||
|
||||
promise.then(function(value) {
|
||||
// success
|
||||
}).catch(function(error) {
|
||||
// failure
|
||||
});
|
||||
```
|
||||
|
||||
Once a promise has been resolved or rejected, it cannot be resolved or rejected
|
||||
again.
|
||||
|
||||
Here is an example of a simple XHR2 wrapper written using RSVP.js:
|
||||
|
||||
```javascript
|
||||
var getJSON = function(url) {
|
||||
var promise = new RSVP.Promise(function(resolve, reject){
|
||||
var client = new XMLHttpRequest();
|
||||
client.open("GET", url);
|
||||
client.onreadystatechange = handler;
|
||||
client.responseType = "json";
|
||||
client.setRequestHeader("Accept", "application/json");
|
||||
client.send();
|
||||
|
||||
function handler() {
|
||||
if (this.readyState === this.DONE) {
|
||||
if (this.status === 200) { resolve(this.response); }
|
||||
else { reject(this); }
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
getJSON("/posts.json").then(function(json) {
|
||||
// continue
|
||||
}).catch(function(error) {
|
||||
// handle errors
|
||||
});
|
||||
```
|
||||
|
||||
### Chaining
|
||||
|
||||
One of the really awesome features of Promises/A+ promises are that they can be
|
||||
chained together. In other words, the return value of the first
|
||||
resolve handler will be passed to the second resolve handler.
|
||||
|
||||
If you return a regular value, it will be passed, as is, to the next handler.
|
||||
|
||||
```javascript
|
||||
getJSON("/posts.json").then(function(json) {
|
||||
return json.post;
|
||||
}).then(function(post) {
|
||||
// proceed
|
||||
});
|
||||
```
|
||||
|
||||
The really awesome part comes when you return a promise from the first handler:
|
||||
|
||||
```javascript
|
||||
getJSON("/post/1.json").then(function(post) {
|
||||
// save off post
|
||||
return getJSON(post.commentURL);
|
||||
}).then(function(comments) {
|
||||
// proceed with access to post and comments
|
||||
});
|
||||
```
|
||||
|
||||
This allows you to flatten out nested callbacks, and is the main feature of
|
||||
promises that prevents "rightward drift" in programs with a lot of asynchronous
|
||||
code.
|
||||
|
||||
Errors also propagate:
|
||||
|
||||
```javascript
|
||||
getJSON("/posts.json").then(function(posts) {
|
||||
|
||||
}).catch(function(error) {
|
||||
// since no rejection handler was passed to the
|
||||
// first `.then`, the error propagates.
|
||||
});
|
||||
```
|
||||
|
||||
You can use this to emulate `try/catch` logic in synchronous code. Simply chain
|
||||
as many resolve callbacks as you want, and add a failure handler at the end to
|
||||
catch errors.
|
||||
|
||||
```javascript
|
||||
getJSON("/post/1.json").then(function(post) {
|
||||
return getJSON(post.commentURL);
|
||||
}).then(function(comments) {
|
||||
// proceed with access to posts and comments
|
||||
}).catch(function(error) {
|
||||
// handle errors in either of the two requests
|
||||
});
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
There are times when dealing with promises that it seems like any errors are
|
||||
being 'swallowed', and not properly raised. This makes it extremely difficult
|
||||
to track down where a given issue is coming from. Thankfully, `RSVP` has a
|
||||
solution for this problem built in.
|
||||
|
||||
You can register functions to be called when an uncaught error occurs within
|
||||
your promises. These callback functions can be anything, but a common practice
|
||||
is to call `console.assert` to dump the error to the console.
|
||||
|
||||
```javascript
|
||||
RSVP.on('error', function(reason) {
|
||||
console.assert(false, reason);
|
||||
});
|
||||
```
|
||||
|
||||
`RSVP` allows Promises to be labeled: `Promise.resolve(value, 'I AM A LABEL')`
|
||||
If provided, this label is passed as the second argument to `RSVP.on('error')`
|
||||
|
||||
```javascript
|
||||
RSVP.on('error', function(reason, label) {
|
||||
if (label) {
|
||||
console.error(label);
|
||||
}
|
||||
|
||||
console.assert(false, reason);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
**NOTE:** promises do allow for errors to be handled asynchronously, so this
|
||||
callback may result in false positives.
|
||||
|
||||
## Finally
|
||||
|
||||
`finally` will be invoked regardless of the promise's fate, just as native
|
||||
try/catch/finally behaves.
|
||||
|
||||
```js
|
||||
findAuthor().catch(function(reason){
|
||||
return findOtherAuthor();
|
||||
}).finally(function(){
|
||||
// author was either found, or not
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Arrays of promises
|
||||
|
||||
Sometimes you might want to work with many promises at once. If you pass an
|
||||
array of promises to the `all()` method it will return a new promise that will
|
||||
be fulfilled when all of the promises in the array have been fulfilled; or
|
||||
rejected immediately if any promise in the array is rejected.
|
||||
|
||||
```javascript
|
||||
var promises = [2, 3, 5, 7, 11, 13].map(function(id){
|
||||
return getJSON("/post/" + id + ".json");
|
||||
});
|
||||
|
||||
RSVP.all(promises).then(function(posts) {
|
||||
// posts contains an array of results for the given promises
|
||||
}).catch(function(reason){
|
||||
// if any of the promises fails.
|
||||
});
|
||||
```
|
||||
|
||||
## Hash of promises
|
||||
|
||||
If you need to reference many promises at once (like `all()`), but would like
|
||||
to avoid encoding the actual promise order you can use `hash()`. If you pass an
|
||||
object literal (where the values are promises) to the `hash()` method it will
|
||||
return a new promise that will be fulfilled when all of the promises have been
|
||||
fulfilled; or rejected immediately if any promise is rejected.
|
||||
|
||||
The key difference to the `all()` function is that both the fulfillment value
|
||||
and the argument to the `hash()` function are object literals. This allows you
|
||||
to simply reference the results directly off the returned object without having
|
||||
to remember the initial order like you would with `all()`.
|
||||
|
||||
```javascript
|
||||
var promises = {
|
||||
posts: getJSON("/posts.json"),
|
||||
users: getJSON("/users.json")
|
||||
};
|
||||
|
||||
RSVP.hash(promises).then(function(results) {
|
||||
console.log(results.users) // print the users.json results
|
||||
console.log(results.posts) // print the posts.json results
|
||||
});
|
||||
```
|
||||
|
||||
## All settled and hash settled
|
||||
|
||||
Sometimes you want to work with several promises at once, but instead of
|
||||
rejecting immediately if any promise is rejected, as with `all()` or `hash()`,
|
||||
you want to be able to inspect the results of all your promises, whether they
|
||||
fulfill or reject. For this purpose, you can use `allSettled()` and
|
||||
`hashSettled()`. These work exactly like `all()` and `hash()`, except that they
|
||||
fulfill with an array or hash (respectively) of the constituent promises'
|
||||
result states. Each state object will either indicate fulfillment or rejection,
|
||||
and provide the corresponding value or reason. The states will take
|
||||
one of the following formats:
|
||||
|
||||
```javascript
|
||||
{ state: 'fulfilled', value: value }
|
||||
or
|
||||
{ state: 'rejected', reason: reason }
|
||||
```
|
||||
|
||||
## Deferred
|
||||
|
||||
> The `RSVP.Promise` constructor is generally a better, less error-prone choice
|
||||
> than `RSVP.defer()`. Promises are recommended unless the specific
|
||||
> properties of deferred are needed.
|
||||
|
||||
Sometimes one needs to create a deferred object, without immediately specifying
|
||||
how it will be resolved. These deferred objects are essentially a wrapper
|
||||
around a promise, whilst providing late access to the `resolve()` and
|
||||
`reject()` methods.
|
||||
|
||||
A deferred object has this form: `{ promise, resolve(x), reject(r) }`.
|
||||
|
||||
```javascript
|
||||
var deferred = RSVP.defer();
|
||||
// ...
|
||||
deferred.promise // access the promise
|
||||
// ...
|
||||
deferred.resolve();
|
||||
|
||||
```
|
||||
|
||||
## TaskJS
|
||||
|
||||
The [TaskJS](https://github.com/mozilla/task.js) library makes it possible to take
|
||||
promises-oriented code and make it synchronous using ES6 generators.
|
||||
|
||||
Let's review an earlier example:
|
||||
|
||||
```javascript
|
||||
getJSON("/post/1.json").then(function(post) {
|
||||
return getJSON(post.commentURL);
|
||||
}).then(function(comments) {
|
||||
// proceed with access to posts and comments
|
||||
}).catch(function(reason) {
|
||||
// handle errors in either of the two requests
|
||||
});
|
||||
```
|
||||
|
||||
Without any changes to the implementation of `getJSON`, you could write
|
||||
the following code with TaskJS:
|
||||
|
||||
```javascript
|
||||
spawn(function *() {
|
||||
try {
|
||||
var post = yield getJSON("/post/1.json");
|
||||
var comments = yield getJSON(post.commentURL);
|
||||
} catch(error) {
|
||||
// handle errors
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
In the above example, `function *` is new syntax in ES6 for
|
||||
[generators](http://wiki.ecmascript.org/doku.php?id=harmony:generators). Inside
|
||||
a generator, `yield` pauses the generator, returning control to the function
|
||||
that invoked the generator. In this case, the invoker is a special function
|
||||
that understands the semantics of Promises/A, and will automatically resume the
|
||||
generator as soon as the promise is resolved.
|
||||
|
||||
The cool thing here is the same promises that work with current
|
||||
JavaScript using `.then` will work seamlessly with TaskJS once a browser
|
||||
has implemented it!
|
||||
|
||||
## Instrumentation
|
||||
|
||||
```js
|
||||
function listener (event) {
|
||||
event.guid // guid of promise. Must be globally unique, not just within the implementation
|
||||
event.childGuid // child of child promise (for chained via `then`)
|
||||
event.eventName // one of ['created', 'chained', 'fulfilled', 'rejected']
|
||||
event.detail // fulfillment value or rejection reason, if applicable
|
||||
event.label // label passed to promise's constructor
|
||||
event.timeStamp // milliseconds elapsed since 1 January 1970 00:00:00 UTC up until now
|
||||
event.stack // stack at the time of the event. (if 'instrument-with-stack' is true)
|
||||
}
|
||||
|
||||
RSVP.configure('instrument', true | false);
|
||||
// capturing the stacks is slow, so you also have to opt in
|
||||
RSVP.configure('instrument-with-stack', true | false);
|
||||
|
||||
// events
|
||||
RSVP.on('created', listener);
|
||||
RSVP.on('chained', listener);
|
||||
RSVP.on('fulfilled', listener);
|
||||
RSVP.on('rejected', listener);
|
||||
```
|
||||
|
||||
Events are only triggered when `RSVP.configure('instrument')` is true, although
|
||||
listeners can be registered at any time.
|
||||
|
||||
## Building & Testing
|
||||
|
||||
Custom tasks:
|
||||
|
||||
* `npm test` - build & test
|
||||
* `npm test:node` - build & test just node
|
||||
* `npm test:server` - build/watch & test
|
||||
* `npm run build` - Build
|
||||
* `npm run build:production` - Build production (with minified output)
|
||||
* `npm start` - build, watch and run interactive server at http://localhost:4200'
|
||||
|
||||
## Releasing
|
||||
|
||||
Check what release-it will do by running `npm run-script dry-run-release`.
|
||||
To actually release, run `node_modules/.bin/release-it`.
|
2474
node_modules/rsvp/dist/es6/rsvp.es.js
generated
vendored
Normal file
2474
node_modules/rsvp/dist/es6/rsvp.es.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/rsvp/dist/es6/rsvp.es.map
generated
vendored
Normal file
1
node_modules/rsvp/dist/es6/rsvp.es.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2526
node_modules/rsvp/dist/rsvp.es.js
generated
vendored
Normal file
2526
node_modules/rsvp/dist/rsvp.es.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/rsvp/dist/rsvp.es.map
generated
vendored
Normal file
1
node_modules/rsvp/dist/rsvp.es.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2559
node_modules/rsvp/dist/rsvp.js
generated
vendored
Normal file
2559
node_modules/rsvp/dist/rsvp.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1
node_modules/rsvp/dist/rsvp.map
generated
vendored
Normal file
1
node_modules/rsvp/dist/rsvp.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
93
node_modules/rsvp/lib/rsvp.js
generated
vendored
Normal file
93
node_modules/rsvp/lib/rsvp.js
generated
vendored
Normal file
|
@ -0,0 +1,93 @@
|
|||
import Promise from './rsvp/promise';
|
||||
import EventTarget from './rsvp/events';
|
||||
import denodeify from './rsvp/node';
|
||||
import all from './rsvp/all';
|
||||
import allSettled from './rsvp/all-settled';
|
||||
import race from './rsvp/race';
|
||||
import hash from './rsvp/hash';
|
||||
import hashSettled from './rsvp/hash-settled';
|
||||
import rethrow from './rsvp/rethrow';
|
||||
import defer from './rsvp/defer';
|
||||
import {
|
||||
config,
|
||||
configure
|
||||
} from './rsvp/config';
|
||||
import map from './rsvp/map';
|
||||
import resolve from './rsvp/resolve';
|
||||
import reject from './rsvp/reject';
|
||||
import filter from './rsvp/filter';
|
||||
import asap from './rsvp/asap';
|
||||
|
||||
// defaults
|
||||
config.async = asap;
|
||||
config.after = cb => setTimeout(cb, 0);
|
||||
const cast = resolve;
|
||||
|
||||
const async = (callback, arg) => config.async(callback, arg);
|
||||
|
||||
function on() {
|
||||
config.on(...arguments);
|
||||
}
|
||||
|
||||
function off() {
|
||||
config.off(...arguments);
|
||||
}
|
||||
|
||||
// Set up instrumentation through `window.__PROMISE_INTRUMENTATION__`
|
||||
if (typeof window !== 'undefined' && typeof window['__PROMISE_INSTRUMENTATION__'] === 'object') {
|
||||
let callbacks = window['__PROMISE_INSTRUMENTATION__'];
|
||||
configure('instrument', true);
|
||||
for (let eventName in callbacks) {
|
||||
if (callbacks.hasOwnProperty(eventName)) {
|
||||
on(eventName, callbacks[eventName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the default export here is for backwards compat:
|
||||
// https://github.com/tildeio/rsvp.js/issues/434
|
||||
export default {
|
||||
asap,
|
||||
cast,
|
||||
Promise,
|
||||
EventTarget,
|
||||
all,
|
||||
allSettled,
|
||||
race,
|
||||
hash,
|
||||
hashSettled,
|
||||
rethrow,
|
||||
defer,
|
||||
denodeify,
|
||||
configure,
|
||||
on,
|
||||
off,
|
||||
resolve,
|
||||
reject,
|
||||
map,
|
||||
async,
|
||||
filter
|
||||
};
|
||||
|
||||
export {
|
||||
asap,
|
||||
cast,
|
||||
Promise,
|
||||
EventTarget,
|
||||
all,
|
||||
allSettled,
|
||||
race,
|
||||
hash,
|
||||
hashSettled,
|
||||
rethrow,
|
||||
defer,
|
||||
denodeify,
|
||||
configure,
|
||||
on,
|
||||
off,
|
||||
resolve,
|
||||
reject,
|
||||
map,
|
||||
async,
|
||||
filter
|
||||
};
|
224
node_modules/rsvp/lib/rsvp/-internal.js
generated
vendored
Normal file
224
node_modules/rsvp/lib/rsvp/-internal.js
generated
vendored
Normal file
|
@ -0,0 +1,224 @@
|
|||
import originalThen from './then';
|
||||
import originalResolve from './promise/resolve';
|
||||
import instrument from './instrument';
|
||||
|
||||
import { config } from './config';
|
||||
import Promise from './promise';
|
||||
|
||||
function withOwnPromise() {
|
||||
return new TypeError('A promises callback cannot return that same promise.');
|
||||
}
|
||||
|
||||
function objectOrFunction(x) {
|
||||
let type = typeof x;
|
||||
return x !== null && (type === 'object' || type === 'function');
|
||||
}
|
||||
|
||||
export function noop() {}
|
||||
|
||||
export const PENDING = void 0;
|
||||
export const FULFILLED = 1;
|
||||
export const REJECTED = 2;
|
||||
|
||||
function tryThen(then, value, fulfillmentHandler, rejectionHandler) {
|
||||
try {
|
||||
then.call(value, fulfillmentHandler, rejectionHandler);
|
||||
} catch(e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
function handleForeignThenable(promise, thenable, then) {
|
||||
config.async(promise => {
|
||||
let sealed = false;
|
||||
let error = tryThen(then,
|
||||
thenable,
|
||||
value => {
|
||||
if (sealed) { return; }
|
||||
sealed = true;
|
||||
if (thenable === value) {
|
||||
fulfill(promise, value);
|
||||
} else {
|
||||
resolve(promise, value);
|
||||
}
|
||||
},
|
||||
reason => {
|
||||
if (sealed) { return; }
|
||||
sealed = true;
|
||||
|
||||
reject(promise, reason);
|
||||
},
|
||||
'Settle: ' + (promise._label || ' unknown promise')
|
||||
);
|
||||
if (!sealed && error) {
|
||||
sealed = true;
|
||||
reject(promise, error);
|
||||
}
|
||||
}, promise);
|
||||
}
|
||||
|
||||
function handleOwnThenable(promise, thenable) {
|
||||
if (thenable._state === FULFILLED) {
|
||||
fulfill(promise, thenable._result);
|
||||
} else if (thenable._state === REJECTED) {
|
||||
thenable._onError = null;
|
||||
reject(promise, thenable._result);
|
||||
} else {
|
||||
subscribe(thenable, undefined, value => {
|
||||
if (thenable === value) {
|
||||
fulfill(promise, value);
|
||||
} else {
|
||||
resolve(promise, value);
|
||||
}
|
||||
}, reason => reject(promise, reason));
|
||||
}
|
||||
}
|
||||
|
||||
export function handleMaybeThenable(promise, maybeThenable, then) {
|
||||
let isOwnThenable =
|
||||
maybeThenable.constructor === promise.constructor &&
|
||||
then === originalThen &&
|
||||
promise.constructor.resolve === originalResolve;
|
||||
|
||||
if (isOwnThenable) {
|
||||
handleOwnThenable(promise, maybeThenable);
|
||||
} else if (typeof then === 'function') {
|
||||
handleForeignThenable(promise, maybeThenable, then);
|
||||
} else {
|
||||
fulfill(promise, maybeThenable);
|
||||
}
|
||||
}
|
||||
|
||||
export function resolve(promise, value) {
|
||||
if (promise === value) {
|
||||
fulfill(promise, value);
|
||||
} else if (objectOrFunction(value)) {
|
||||
let then;
|
||||
try {
|
||||
then = value.then;
|
||||
} catch (error) {
|
||||
reject(promise, error);
|
||||
return;
|
||||
}
|
||||
handleMaybeThenable(promise, value, then);
|
||||
} else {
|
||||
fulfill(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
export function publishRejection(promise) {
|
||||
if (promise._onError) {
|
||||
promise._onError(promise._result);
|
||||
}
|
||||
|
||||
publish(promise);
|
||||
}
|
||||
|
||||
export function fulfill(promise, value) {
|
||||
if (promise._state !== PENDING) { return; }
|
||||
|
||||
promise._result = value;
|
||||
promise._state = FULFILLED;
|
||||
|
||||
if (promise._subscribers.length === 0) {
|
||||
if (config.instrument) {
|
||||
instrument('fulfilled', promise);
|
||||
}
|
||||
} else {
|
||||
config.async(publish, promise);
|
||||
}
|
||||
}
|
||||
|
||||
export function reject(promise, reason) {
|
||||
if (promise._state !== PENDING) { return; }
|
||||
promise._state = REJECTED;
|
||||
promise._result = reason;
|
||||
config.async(publishRejection, promise);
|
||||
}
|
||||
|
||||
export function subscribe(parent, child, onFulfillment, onRejection) {
|
||||
let subscribers = parent._subscribers;
|
||||
let length = subscribers.length;
|
||||
|
||||
parent._onError = null;
|
||||
|
||||
subscribers[length] = child;
|
||||
subscribers[length + FULFILLED] = onFulfillment;
|
||||
subscribers[length + REJECTED] = onRejection;
|
||||
|
||||
if (length === 0 && parent._state) {
|
||||
config.async(publish, parent);
|
||||
}
|
||||
}
|
||||
|
||||
export function publish(promise) {
|
||||
let subscribers = promise._subscribers;
|
||||
let settled = promise._state;
|
||||
|
||||
if (config.instrument) {
|
||||
instrument(settled === FULFILLED ? 'fulfilled' : 'rejected', promise);
|
||||
}
|
||||
|
||||
if (subscribers.length === 0) { return; }
|
||||
|
||||
let child, callback, result = promise._result;
|
||||
|
||||
for (let i = 0; i < subscribers.length; i += 3) {
|
||||
child = subscribers[i];
|
||||
callback = subscribers[i + settled];
|
||||
|
||||
if (child) {
|
||||
invokeCallback(settled, child, callback, result);
|
||||
} else {
|
||||
callback(result);
|
||||
}
|
||||
}
|
||||
|
||||
promise._subscribers.length = 0;
|
||||
}
|
||||
|
||||
export function invokeCallback(state, promise, callback, result) {
|
||||
let hasCallback = typeof callback === 'function';
|
||||
let value, succeeded = true, error;
|
||||
|
||||
if (hasCallback) {
|
||||
try {
|
||||
value = callback(result)
|
||||
} catch (e) {
|
||||
succeeded = false;
|
||||
error = e;
|
||||
}
|
||||
} else {
|
||||
value = result;
|
||||
}
|
||||
|
||||
if (promise._state !== PENDING) {
|
||||
// noop
|
||||
} else if (value === promise) {
|
||||
reject(promise, withOwnPromise());
|
||||
} else if (succeeded === false) {
|
||||
reject(promise, error);
|
||||
} else if (hasCallback) {
|
||||
resolve(promise, value);
|
||||
} else if (state === FULFILLED) {
|
||||
fulfill(promise, value);
|
||||
} else if (state === REJECTED) {
|
||||
reject(promise, value);
|
||||
}
|
||||
}
|
||||
|
||||
export function initializePromise(promise, resolver) {
|
||||
let resolved = false;
|
||||
try {
|
||||
resolver(value => {
|
||||
if (resolved) { return; }
|
||||
resolved = true;
|
||||
resolve(promise, value);
|
||||
}, reason => {
|
||||
if (resolved) { return; }
|
||||
resolved = true;
|
||||
reject(promise, reason);
|
||||
});
|
||||
} catch(e) {
|
||||
reject(promise, e);
|
||||
}
|
||||
}
|
81
node_modules/rsvp/lib/rsvp/all-settled.js
generated
vendored
Normal file
81
node_modules/rsvp/lib/rsvp/all-settled.js
generated
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
import {
|
||||
default as Enumerator,
|
||||
setSettledResult
|
||||
} from './enumerator';
|
||||
import Promise from './promise';
|
||||
|
||||
/**
|
||||
@module rsvp
|
||||
@public
|
||||
**/
|
||||
|
||||
class AllSettled extends Enumerator {
|
||||
constructor(Constructor, entries, label) {
|
||||
super(Constructor, entries, false /* don't abort on reject */, label);
|
||||
}
|
||||
}
|
||||
|
||||
AllSettled.prototype._setResultAt = setSettledResult;
|
||||
|
||||
/**
|
||||
`RSVP.allSettled` is similar to `RSVP.all`, but instead of implementing
|
||||
a fail-fast method, it waits until all the promises have returned and
|
||||
shows you all the results. This is useful if you want to handle multiple
|
||||
promises' failure states together as a set.
|
||||
|
||||
Returns a promise that is fulfilled when all the given promises have been
|
||||
settled. The return promise is fulfilled with an array of the states of
|
||||
the promises passed into the `promises` array argument.
|
||||
|
||||
Each state object will either indicate fulfillment or rejection, and
|
||||
provide the corresponding value or reason. The states will take one of
|
||||
the following formats:
|
||||
|
||||
```javascript
|
||||
{ state: 'fulfilled', value: value }
|
||||
or
|
||||
{ state: 'rejected', reason: reason }
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
let promise1 = RSVP.Promise.resolve(1);
|
||||
let promise2 = RSVP.Promise.reject(new Error('2'));
|
||||
let promise3 = RSVP.Promise.reject(new Error('3'));
|
||||
let promises = [ promise1, promise2, promise3 ];
|
||||
|
||||
RSVP.allSettled(promises).then(function(array){
|
||||
// array == [
|
||||
// { state: 'fulfilled', value: 1 },
|
||||
// { state: 'rejected', reason: Error },
|
||||
// { state: 'rejected', reason: Error }
|
||||
// ]
|
||||
// Note that for the second item, reason.message will be '2', and for the
|
||||
// third item, reason.message will be '3'.
|
||||
}, function(error) {
|
||||
// Not run. (This block would only be called if allSettled had failed,
|
||||
// for instance if passed an incorrect argument type.)
|
||||
});
|
||||
```
|
||||
|
||||
@method allSettled
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {Array} entries
|
||||
@param {String} [label] - optional string that describes the promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} promise that is fulfilled with an array of the settled
|
||||
states of the constituent promises.
|
||||
*/
|
||||
|
||||
export default function allSettled(entries, label) {
|
||||
if (!Array.isArray(entries)) {
|
||||
return Promise.reject(new TypeError("Promise.allSettled must be called with an array"), label);
|
||||
}
|
||||
|
||||
return new AllSettled(Promise, entries, label).promise;
|
||||
}
|
||||
|
||||
|
16
node_modules/rsvp/lib/rsvp/all.js
generated
vendored
Normal file
16
node_modules/rsvp/lib/rsvp/all.js
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
import Promise from "./promise";
|
||||
|
||||
/**
|
||||
This is a convenient alias for `Promise.all`.
|
||||
|
||||
@method all
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {Array} array Array of promises.
|
||||
@param {String} [label] An optional label. This is useful
|
||||
for tooling.
|
||||
*/
|
||||
export default function all(array, label) {
|
||||
return Promise.all(array, label);
|
||||
}
|
106
node_modules/rsvp/lib/rsvp/asap.js
generated
vendored
Normal file
106
node_modules/rsvp/lib/rsvp/asap.js
generated
vendored
Normal file
|
@ -0,0 +1,106 @@
|
|||
let len = 0;
|
||||
let vertxNext;
|
||||
export default function asap(callback, arg) {
|
||||
queue[len] = callback;
|
||||
queue[len + 1] = arg;
|
||||
len += 2;
|
||||
if (len === 2) {
|
||||
// If len is 1, that means that we need to schedule an async flush.
|
||||
// If additional callbacks are queued before the queue is flushed, they
|
||||
// will be processed by this flush that we are scheduling.
|
||||
scheduleFlush();
|
||||
}
|
||||
}
|
||||
|
||||
const browserWindow = (typeof window !== 'undefined') ? window : undefined;
|
||||
const browserGlobal = browserWindow || {};
|
||||
const BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
||||
const isNode = typeof self === 'undefined' &&
|
||||
typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
|
||||
|
||||
// test for web worker but not in IE10
|
||||
const isWorker = typeof Uint8ClampedArray !== 'undefined' &&
|
||||
typeof importScripts !== 'undefined' &&
|
||||
typeof MessageChannel !== 'undefined';
|
||||
|
||||
// node
|
||||
function useNextTick() {
|
||||
let nextTick = process.nextTick;
|
||||
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
||||
// setImmediate should be used instead instead
|
||||
let version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/);
|
||||
if (Array.isArray(version) && version[1] === '0' && version[2] === '10') {
|
||||
nextTick = setImmediate;
|
||||
}
|
||||
return () => nextTick(flush);
|
||||
}
|
||||
|
||||
// vertx
|
||||
function useVertxTimer() {
|
||||
if (typeof vertxNext !== 'undefined') {
|
||||
return function() {
|
||||
vertxNext(flush);
|
||||
};
|
||||
}
|
||||
return useSetTimeout();
|
||||
}
|
||||
|
||||
function useMutationObserver() {
|
||||
let iterations = 0;
|
||||
let observer = new BrowserMutationObserver(flush);
|
||||
let node = document.createTextNode('');
|
||||
observer.observe(node, { characterData: true });
|
||||
|
||||
return () => node.data = (iterations = ++iterations % 2);
|
||||
}
|
||||
|
||||
// web worker
|
||||
function useMessageChannel() {
|
||||
let channel = new MessageChannel();
|
||||
channel.port1.onmessage = flush;
|
||||
return () => channel.port2.postMessage(0);
|
||||
}
|
||||
|
||||
function useSetTimeout() {
|
||||
return () => setTimeout(flush, 1);
|
||||
}
|
||||
|
||||
const queue = new Array(1000);
|
||||
|
||||
function flush() {
|
||||
for (let i = 0; i < len; i+=2) {
|
||||
let callback = queue[i];
|
||||
let arg = queue[i+1];
|
||||
|
||||
callback(arg);
|
||||
|
||||
queue[i] = undefined;
|
||||
queue[i+1] = undefined;
|
||||
}
|
||||
|
||||
len = 0;
|
||||
}
|
||||
|
||||
function attemptVertex() {
|
||||
try {
|
||||
const vertx = Function('return this')().require('vertx');
|
||||
vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
||||
return useVertxTimer();
|
||||
} catch(e) {
|
||||
return useSetTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
let scheduleFlush;
|
||||
// Decide what async method to use to triggering processing of queued callbacks:
|
||||
if (isNode) {
|
||||
scheduleFlush = useNextTick();
|
||||
} else if (BrowserMutationObserver) {
|
||||
scheduleFlush = useMutationObserver();
|
||||
} else if (isWorker) {
|
||||
scheduleFlush = useMessageChannel();
|
||||
} else if (browserWindow === undefined && typeof require === 'function') {
|
||||
scheduleFlush = attemptVertex();
|
||||
} else {
|
||||
scheduleFlush = useSetTimeout();
|
||||
}
|
20
node_modules/rsvp/lib/rsvp/config.js
generated
vendored
Normal file
20
node_modules/rsvp/lib/rsvp/config.js
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
import EventTarget from './events';
|
||||
|
||||
const config = {
|
||||
instrument: false
|
||||
};
|
||||
|
||||
EventTarget['mixin'](config);
|
||||
|
||||
function configure(name, value) {
|
||||
if (arguments.length === 2) {
|
||||
config[name] = value;
|
||||
} else {
|
||||
return config[name];
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
config,
|
||||
configure
|
||||
};
|
46
node_modules/rsvp/lib/rsvp/defer.js
generated
vendored
Normal file
46
node_modules/rsvp/lib/rsvp/defer.js
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
import Promise from "./promise";
|
||||
|
||||
/**
|
||||
`defer` returns an object similar to jQuery's `$.Deferred`.
|
||||
`defer` should be used when porting over code reliant on `$.Deferred`'s
|
||||
interface. New code should use the `Promise` constructor instead.
|
||||
|
||||
The object returned from `defer` is a plain object with three properties:
|
||||
|
||||
* promise - an `Promise`.
|
||||
* reject - a function that causes the `promise` property on this object to
|
||||
become rejected
|
||||
* resolve - a function that causes the `promise` property on this object to
|
||||
become fulfilled.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
let deferred = defer();
|
||||
|
||||
deferred.resolve("Success!");
|
||||
|
||||
deferred.promise.then(function(value){
|
||||
// value here is "Success!"
|
||||
});
|
||||
```
|
||||
|
||||
@method defer
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {String} [label] optional string for labeling the promise.
|
||||
Useful for tooling.
|
||||
@return {Object}
|
||||
*/
|
||||
|
||||
export default function defer(label) {
|
||||
let deferred = { resolve: undefined, reject: undefined };
|
||||
|
||||
deferred.promise = new Promise((resolve, reject) => {
|
||||
deferred.resolve = resolve;
|
||||
deferred.reject = reject;
|
||||
}, label);
|
||||
|
||||
return deferred;
|
||||
}
|
136
node_modules/rsvp/lib/rsvp/enumerator.js
generated
vendored
Normal file
136
node_modules/rsvp/lib/rsvp/enumerator.js
generated
vendored
Normal file
|
@ -0,0 +1,136 @@
|
|||
import {
|
||||
noop,
|
||||
resolve,
|
||||
handleMaybeThenable,
|
||||
reject,
|
||||
fulfill,
|
||||
subscribe,
|
||||
FULFILLED,
|
||||
REJECTED,
|
||||
PENDING,
|
||||
} from './-internal';
|
||||
|
||||
import { default as OwnPromise } from './promise';
|
||||
import ownThen from './then';
|
||||
import ownResolve from './promise/resolve';
|
||||
|
||||
export default class Enumerator {
|
||||
constructor(Constructor, input, abortOnReject, label) {
|
||||
this._instanceConstructor = Constructor;
|
||||
this.promise = new Constructor(noop, label);
|
||||
this._abortOnReject = abortOnReject;
|
||||
this._isUsingOwnPromise = Constructor === OwnPromise;
|
||||
this._isUsingOwnResolve = Constructor.resolve === ownResolve;
|
||||
|
||||
this._init(...arguments);
|
||||
}
|
||||
|
||||
_init(Constructor, input) {
|
||||
let len = input.length || 0;
|
||||
this.length = len;
|
||||
this._remaining = len;
|
||||
this._result = new Array(len);
|
||||
|
||||
this._enumerate(input);
|
||||
}
|
||||
|
||||
_enumerate(input) {
|
||||
let length = this.length;
|
||||
let promise = this.promise;
|
||||
|
||||
for (let i = 0; promise._state === PENDING && i < length; i++) {
|
||||
this._eachEntry(input[i], i, true);
|
||||
}
|
||||
this._checkFullfillment();
|
||||
}
|
||||
|
||||
_checkFullfillment() {
|
||||
if (this._remaining === 0) {
|
||||
let result = this._result;
|
||||
fulfill(this.promise, result);
|
||||
this._result = null
|
||||
}
|
||||
}
|
||||
|
||||
_settleMaybeThenable(entry, i, firstPass) {
|
||||
let c = this._instanceConstructor;
|
||||
|
||||
if (this._isUsingOwnResolve) {
|
||||
let then, error, succeeded = true;
|
||||
try {
|
||||
then = entry.then;
|
||||
} catch (e) {
|
||||
succeeded = false;
|
||||
error = e;
|
||||
}
|
||||
|
||||
if (then === ownThen && entry._state !== PENDING) {
|
||||
entry._onError = null;
|
||||
this._settledAt(entry._state, i, entry._result, firstPass);
|
||||
} else if (typeof then !== 'function') {
|
||||
this._settledAt(FULFILLED, i, entry, firstPass);
|
||||
} else if (this._isUsingOwnPromise) {
|
||||
let promise = new c(noop);
|
||||
if (succeeded === false) {
|
||||
reject(promise, error);
|
||||
} else {
|
||||
handleMaybeThenable(promise, entry, then);
|
||||
this._willSettleAt(promise, i, firstPass);
|
||||
}
|
||||
} else {
|
||||
this._willSettleAt(new c(resolve => resolve(entry)), i, firstPass);
|
||||
}
|
||||
} else {
|
||||
this._willSettleAt(c.resolve(entry), i, firstPass);
|
||||
}
|
||||
}
|
||||
|
||||
_eachEntry(entry, i, firstPass) {
|
||||
if (entry !== null && typeof entry === 'object') {
|
||||
this._settleMaybeThenable(entry, i, firstPass);
|
||||
} else {
|
||||
this._setResultAt(FULFILLED, i, entry, firstPass);
|
||||
}
|
||||
}
|
||||
|
||||
_settledAt(state, i, value, firstPass) {
|
||||
let promise = this.promise;
|
||||
|
||||
if (promise._state === PENDING) {
|
||||
if (this._abortOnReject && state === REJECTED) {
|
||||
reject(promise, value);
|
||||
} else {
|
||||
this._setResultAt(state, i, value, firstPass);
|
||||
this._checkFullfillment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_setResultAt(state, i, value, firstPass) {
|
||||
this._remaining--;
|
||||
this._result[i] = value;
|
||||
}
|
||||
|
||||
_willSettleAt(promise, i, firstPass) {
|
||||
subscribe(
|
||||
promise, undefined,
|
||||
value => this._settledAt(FULFILLED, i, value, firstPass),
|
||||
reason => this._settledAt(REJECTED, i, reason, firstPass)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function setSettledResult(state, i, value) {
|
||||
this._remaining--;
|
||||
if (state === FULFILLED) {
|
||||
this._result[i] = {
|
||||
state: 'fulfilled',
|
||||
value: value
|
||||
};
|
||||
} else {
|
||||
this._result[i] = {
|
||||
state: 'rejected',
|
||||
reason: value
|
||||
};
|
||||
}
|
||||
}
|
205
node_modules/rsvp/lib/rsvp/events.js
generated
vendored
Normal file
205
node_modules/rsvp/lib/rsvp/events.js
generated
vendored
Normal file
|
@ -0,0 +1,205 @@
|
|||
|
||||
function callbacksFor(object) {
|
||||
let callbacks = object._promiseCallbacks;
|
||||
|
||||
if (!callbacks) {
|
||||
callbacks = object._promiseCallbacks = {};
|
||||
}
|
||||
|
||||
return callbacks;
|
||||
}
|
||||
|
||||
/**
|
||||
@class EventTarget
|
||||
@for rsvp
|
||||
@public
|
||||
*/
|
||||
export default {
|
||||
|
||||
/**
|
||||
`EventTarget.mixin` extends an object with EventTarget methods. For
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
import EventTarget from 'rsvp';
|
||||
|
||||
let object = {};
|
||||
|
||||
EventTarget.mixin(object);
|
||||
|
||||
object.on('finished', function(event) {
|
||||
// handle event
|
||||
});
|
||||
|
||||
object.trigger('finished', { detail: value });
|
||||
```
|
||||
|
||||
`EventTarget.mixin` also works with prototypes:
|
||||
|
||||
```javascript
|
||||
import EventTarget from 'rsvp';
|
||||
|
||||
let Person = function() {};
|
||||
EventTarget.mixin(Person.prototype);
|
||||
|
||||
let yehuda = new Person();
|
||||
let tom = new Person();
|
||||
|
||||
yehuda.on('poke', function(event) {
|
||||
console.log('Yehuda says OW');
|
||||
});
|
||||
|
||||
tom.on('poke', function(event) {
|
||||
console.log('Tom says OW');
|
||||
});
|
||||
|
||||
yehuda.trigger('poke');
|
||||
tom.trigger('poke');
|
||||
```
|
||||
|
||||
@method mixin
|
||||
@for rsvp
|
||||
@private
|
||||
@param {Object} object object to extend with EventTarget methods
|
||||
*/
|
||||
mixin(object) {
|
||||
object.on = this.on;
|
||||
object.off = this.off;
|
||||
object.trigger = this.trigger;
|
||||
object._promiseCallbacks = undefined;
|
||||
return object;
|
||||
},
|
||||
|
||||
/**
|
||||
Registers a callback to be executed when `eventName` is triggered
|
||||
|
||||
```javascript
|
||||
object.on('event', function(eventInfo){
|
||||
// handle the event
|
||||
});
|
||||
|
||||
object.trigger('event');
|
||||
```
|
||||
|
||||
@method on
|
||||
@for EventTarget
|
||||
@private
|
||||
@param {String} eventName name of the event to listen for
|
||||
@param {Function} callback function to be called when the event is triggered.
|
||||
*/
|
||||
on(eventName, callback) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw new TypeError('Callback must be a function');
|
||||
}
|
||||
|
||||
let allCallbacks = callbacksFor(this);
|
||||
let callbacks = allCallbacks[eventName];
|
||||
|
||||
if (!callbacks) {
|
||||
callbacks = allCallbacks[eventName] = [];
|
||||
}
|
||||
|
||||
if (callbacks.indexOf(callback) === -1) {
|
||||
callbacks.push(callback);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
You can use `off` to stop firing a particular callback for an event:
|
||||
|
||||
```javascript
|
||||
function doStuff() { // do stuff! }
|
||||
object.on('stuff', doStuff);
|
||||
|
||||
object.trigger('stuff'); // doStuff will be called
|
||||
|
||||
// Unregister ONLY the doStuff callback
|
||||
object.off('stuff', doStuff);
|
||||
object.trigger('stuff'); // doStuff will NOT be called
|
||||
```
|
||||
|
||||
If you don't pass a `callback` argument to `off`, ALL callbacks for the
|
||||
event will not be executed when the event fires. For example:
|
||||
|
||||
```javascript
|
||||
let callback1 = function(){};
|
||||
let callback2 = function(){};
|
||||
|
||||
object.on('stuff', callback1);
|
||||
object.on('stuff', callback2);
|
||||
|
||||
object.trigger('stuff'); // callback1 and callback2 will be executed.
|
||||
|
||||
object.off('stuff');
|
||||
object.trigger('stuff'); // callback1 and callback2 will not be executed!
|
||||
```
|
||||
|
||||
@method off
|
||||
@for rsvp
|
||||
@private
|
||||
@param {String} eventName event to stop listening to
|
||||
@param {Function} [callback] optional argument. If given, only the function
|
||||
given will be removed from the event's callback queue. If no `callback`
|
||||
argument is given, all callbacks will be removed from the event's callback
|
||||
queue.
|
||||
*/
|
||||
off(eventName, callback) {
|
||||
let allCallbacks = callbacksFor(this);
|
||||
|
||||
if (!callback) {
|
||||
allCallbacks[eventName] = [];
|
||||
return;
|
||||
}
|
||||
|
||||
let callbacks = allCallbacks[eventName];
|
||||
let index = callbacks.indexOf(callback);
|
||||
|
||||
if (index !== -1) {
|
||||
callbacks.splice(index, 1);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
Use `trigger` to fire custom events. For example:
|
||||
|
||||
```javascript
|
||||
object.on('foo', function(){
|
||||
console.log('foo event happened!');
|
||||
});
|
||||
object.trigger('foo');
|
||||
// 'foo event happened!' logged to the console
|
||||
```
|
||||
|
||||
You can also pass a value as a second argument to `trigger` that will be
|
||||
passed as an argument to all event listeners for the event:
|
||||
|
||||
```javascript
|
||||
object.on('foo', function(value){
|
||||
console.log(value.name);
|
||||
});
|
||||
|
||||
object.trigger('foo', { name: 'bar' });
|
||||
// 'bar' logged to the console
|
||||
```
|
||||
|
||||
@method trigger
|
||||
@for rsvp
|
||||
@private
|
||||
@param {String} eventName name of the event to be triggered
|
||||
@param {*} [options] optional value to be passed to any event handlers for
|
||||
the given `eventName`
|
||||
*/
|
||||
trigger(eventName, options, label) {
|
||||
let allCallbacks = callbacksFor(this);
|
||||
|
||||
let callbacks = allCallbacks[eventName];
|
||||
if (callbacks) {
|
||||
// Don't cache the callbacks.length since it may grow
|
||||
let callback;
|
||||
for (let i = 0; i < callbacks.length; i++) {
|
||||
callback = callbacks[i];
|
||||
callback(options, label);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
145
node_modules/rsvp/lib/rsvp/filter.js
generated
vendored
Normal file
145
node_modules/rsvp/lib/rsvp/filter.js
generated
vendored
Normal file
|
@ -0,0 +1,145 @@
|
|||
import Promise from './promise';
|
||||
import { MapEnumerator } from './map';
|
||||
import {
|
||||
fulfill,
|
||||
REJECTED
|
||||
} from './-internal';
|
||||
|
||||
const EMPTY_OBJECT = {};
|
||||
|
||||
class FilterEnumerator extends MapEnumerator {
|
||||
|
||||
_checkFullfillment() {
|
||||
if (this._remaining === 0 && this._result !== null) {
|
||||
let result = this._result.filter((val) => val !== EMPTY_OBJECT);
|
||||
fulfill(this.promise, result);
|
||||
this._result = null;
|
||||
}
|
||||
}
|
||||
|
||||
_setResultAt(state, i, value, firstPass) {
|
||||
if (firstPass) {
|
||||
this._result[i] = value;
|
||||
let val, succeeded = true;
|
||||
try {
|
||||
val = this._mapFn(value, i);
|
||||
} catch (error) {
|
||||
succeeded = false;
|
||||
this._settledAt(REJECTED, i, error, false);
|
||||
}
|
||||
if (succeeded) {
|
||||
this._eachEntry(val, i, false);
|
||||
}
|
||||
} else {
|
||||
this._remaining--;
|
||||
if (!value) {
|
||||
this._result[i] = EMPTY_OBJECT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
`filter` is similar to JavaScript's native `filter` method.
|
||||
`filterFn` is eagerly called meaning that as soon as any promise
|
||||
resolves its value will be passed to `filterFn`. `filter` returns
|
||||
a promise that will become fulfilled with the result of running
|
||||
`filterFn` on the values the promises become fulfilled with.
|
||||
|
||||
For example:
|
||||
|
||||
```javascript
|
||||
import { filter, resolve } from 'rsvp';
|
||||
|
||||
let promise1 = resolve(1);
|
||||
let promise2 = resolve(2);
|
||||
let promise3 = resolve(3);
|
||||
|
||||
let promises = [promise1, promise2, promise3];
|
||||
|
||||
let filterFn = function(item){
|
||||
return item > 1;
|
||||
};
|
||||
|
||||
filter(promises, filterFn).then(function(result){
|
||||
// result is [ 2, 3 ]
|
||||
});
|
||||
```
|
||||
|
||||
If any of the `promises` given to `filter` are rejected, the first promise
|
||||
that is rejected will be given as an argument to the returned promise's
|
||||
rejection handler. For example:
|
||||
|
||||
```javascript
|
||||
import { filter, reject, resolve } from 'rsvp';
|
||||
|
||||
let promise1 = resolve(1);
|
||||
let promise2 = reject(new Error('2'));
|
||||
let promise3 = reject(new Error('3'));
|
||||
let promises = [ promise1, promise2, promise3 ];
|
||||
|
||||
let filterFn = function(item){
|
||||
return item > 1;
|
||||
};
|
||||
|
||||
filter(promises, filterFn).then(function(array){
|
||||
// Code here never runs because there are rejected promises!
|
||||
}, function(reason) {
|
||||
// reason.message === '2'
|
||||
});
|
||||
```
|
||||
|
||||
`filter` will also wait for any promises returned from `filterFn`.
|
||||
For instance, you may want to fetch a list of users then return a subset
|
||||
of those users based on some asynchronous operation:
|
||||
|
||||
```javascript
|
||||
import { filter, resolve } from 'rsvp';
|
||||
|
||||
let alice = { name: 'alice' };
|
||||
let bob = { name: 'bob' };
|
||||
let users = [ alice, bob ];
|
||||
|
||||
let promises = users.map(function(user){
|
||||
return resolve(user);
|
||||
});
|
||||
|
||||
let filterFn = function(user){
|
||||
// Here, Alice has permissions to create a blog post, but Bob does not.
|
||||
return getPrivilegesForUser(user).then(function(privs){
|
||||
return privs.can_create_blog_post === true;
|
||||
});
|
||||
};
|
||||
filter(promises, filterFn).then(function(users){
|
||||
// true, because the server told us only Alice can create a blog post.
|
||||
users.length === 1;
|
||||
// false, because Alice is the only user present in `users`
|
||||
users[0] === bob;
|
||||
});
|
||||
```
|
||||
|
||||
@method filter
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {Array} promises
|
||||
@param {Function} filterFn - function to be called on each resolved value to
|
||||
filter the final results.
|
||||
@param {String} [label] optional string describing the promise. Useful for
|
||||
tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
|
||||
export default function filter(promises, filterFn, label) {
|
||||
if (typeof filterFn !== 'function') {
|
||||
return Promise.reject(new TypeError("filter expects function as a second argument"), label);
|
||||
}
|
||||
|
||||
return Promise.resolve(promises, label)
|
||||
.then(function(promises) {
|
||||
if (!Array.isArray(promises)) {
|
||||
throw new TypeError("filter must be called with an array");
|
||||
}
|
||||
return new FilterEnumerator(Promise, promises, filterFn, label).promise;
|
||||
});
|
||||
}
|
134
node_modules/rsvp/lib/rsvp/hash-settled.js
generated
vendored
Normal file
134
node_modules/rsvp/lib/rsvp/hash-settled.js
generated
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
import Promise from './promise';
|
||||
import {
|
||||
default as Enumerator,
|
||||
setSettledResult
|
||||
} from './enumerator';
|
||||
import PromiseHash from './promise-hash';
|
||||
|
||||
class HashSettled extends PromiseHash {
|
||||
constructor(Constructor, object, label) {
|
||||
super(Constructor, object, false, label);
|
||||
}
|
||||
}
|
||||
|
||||
HashSettled.prototype._setResultAt = setSettledResult;
|
||||
|
||||
/**
|
||||
`hashSettled` is similar to `allSettled`, but takes an object
|
||||
instead of an array for its `promises` argument.
|
||||
|
||||
Unlike `all` or `hash`, which implement a fail-fast method,
|
||||
but like `allSettled`, `hashSettled` waits until all the
|
||||
constituent promises have returned and then shows you all the results
|
||||
with their states and values/reasons. This is useful if you want to
|
||||
handle multiple promises' failure states together as a set.
|
||||
|
||||
Returns a promise that is fulfilled when all the given promises have been
|
||||
settled, or rejected if the passed parameters are invalid.
|
||||
|
||||
The returned promise is fulfilled with a hash that has the same key names as
|
||||
the `promises` object argument. If any of the values in the object are not
|
||||
promises, they will be copied over to the fulfilled object and marked with state
|
||||
'fulfilled'.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
import { hashSettled, resolve } from 'rsvp';
|
||||
|
||||
let promises = {
|
||||
myPromise: resolve(1),
|
||||
yourPromise: resolve(2),
|
||||
theirPromise: resolve(3),
|
||||
notAPromise: 4
|
||||
};
|
||||
|
||||
hashSettled(promises).then(function(hash){
|
||||
// hash here is an object that looks like:
|
||||
// {
|
||||
// myPromise: { state: 'fulfilled', value: 1 },
|
||||
// yourPromise: { state: 'fulfilled', value: 2 },
|
||||
// theirPromise: { state: 'fulfilled', value: 3 },
|
||||
// notAPromise: { state: 'fulfilled', value: 4 }
|
||||
// }
|
||||
});
|
||||
```
|
||||
|
||||
If any of the `promises` given to `hash` are rejected, the state will
|
||||
be set to 'rejected' and the reason for rejection provided.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
import { hashSettled, reject, resolve } from 'rsvp';
|
||||
|
||||
let promises = {
|
||||
myPromise: resolve(1),
|
||||
rejectedPromise: reject(new Error('rejection')),
|
||||
anotherRejectedPromise: reject(new Error('more rejection')),
|
||||
};
|
||||
|
||||
hashSettled(promises).then(function(hash){
|
||||
// hash here is an object that looks like:
|
||||
// {
|
||||
// myPromise: { state: 'fulfilled', value: 1 },
|
||||
// rejectedPromise: { state: 'rejected', reason: Error },
|
||||
// anotherRejectedPromise: { state: 'rejected', reason: Error },
|
||||
// }
|
||||
// Note that for rejectedPromise, reason.message == 'rejection',
|
||||
// and for anotherRejectedPromise, reason.message == 'more rejection'.
|
||||
});
|
||||
```
|
||||
|
||||
An important note: `hashSettled` is intended for plain JavaScript objects that
|
||||
are just a set of keys and values. `hashSettled` will NOT preserve prototype
|
||||
chains.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
import Promise, { hashSettled, resolve } from 'rsvp';
|
||||
|
||||
function MyConstructor(){
|
||||
this.example = resolve('Example');
|
||||
}
|
||||
|
||||
MyConstructor.prototype = {
|
||||
protoProperty: Promise.resolve('Proto Property')
|
||||
};
|
||||
|
||||
let myObject = new MyConstructor();
|
||||
|
||||
hashSettled(myObject).then(function(hash){
|
||||
// protoProperty will not be present, instead you will just have an
|
||||
// object that looks like:
|
||||
// {
|
||||
// example: { state: 'fulfilled', value: 'Example' }
|
||||
// }
|
||||
//
|
||||
// hash.hasOwnProperty('protoProperty'); // false
|
||||
// 'undefined' === typeof hash.protoProperty
|
||||
});
|
||||
```
|
||||
|
||||
@method hashSettled
|
||||
@public
|
||||
@for rsvp
|
||||
@param {Object} object
|
||||
@param {String} [label] optional string that describes the promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} promise that is fulfilled when when all properties of `promises`
|
||||
have been settled.
|
||||
@static
|
||||
*/
|
||||
|
||||
export default function hashSettled(object, label) {
|
||||
return Promise.resolve(object, label)
|
||||
.then(function(object) {
|
||||
if (object === null || typeof object !== 'object') {
|
||||
throw new TypeError("hashSettled must be called with an object");
|
||||
}
|
||||
|
||||
return new HashSettled(Promise, object, false, label).promise;
|
||||
});
|
||||
}
|
102
node_modules/rsvp/lib/rsvp/hash.js
generated
vendored
Normal file
102
node_modules/rsvp/lib/rsvp/hash.js
generated
vendored
Normal file
|
@ -0,0 +1,102 @@
|
|||
import Promise from './promise';
|
||||
import PromiseHash from './promise-hash';
|
||||
|
||||
/**
|
||||
`hash` is similar to `all`, but takes an object instead of an array
|
||||
for its `promises` argument.
|
||||
|
||||
Returns a promise that is fulfilled when all the given promises have been
|
||||
fulfilled, or rejected if any of them become rejected. The returned promise
|
||||
is fulfilled with a hash that has the same key names as the `promises` object
|
||||
argument. If any of the values in the object are not promises, they will
|
||||
simply be copied over to the fulfilled object.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
let promises = {
|
||||
myPromise: resolve(1),
|
||||
yourPromise: resolve(2),
|
||||
theirPromise: resolve(3),
|
||||
notAPromise: 4
|
||||
};
|
||||
|
||||
hash(promises).then(function(hash){
|
||||
// hash here is an object that looks like:
|
||||
// {
|
||||
// myPromise: 1,
|
||||
// yourPromise: 2,
|
||||
// theirPromise: 3,
|
||||
// notAPromise: 4
|
||||
// }
|
||||
});
|
||||
```
|
||||
|
||||
If any of the `promises` given to `hash` are rejected, the first promise
|
||||
that is rejected will be given as the reason to the rejection handler.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
let promises = {
|
||||
myPromise: resolve(1),
|
||||
rejectedPromise: reject(new Error('rejectedPromise')),
|
||||
anotherRejectedPromise: reject(new Error('anotherRejectedPromise')),
|
||||
};
|
||||
|
||||
hash(promises).then(function(hash){
|
||||
// Code here never runs because there are rejected promises!
|
||||
}, function(reason) {
|
||||
// reason.message === 'rejectedPromise'
|
||||
});
|
||||
```
|
||||
|
||||
An important note: `hash` is intended for plain JavaScript objects that
|
||||
are just a set of keys and values. `hash` will NOT preserve prototype
|
||||
chains.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
import { hash, resolve } from 'rsvp';
|
||||
function MyConstructor(){
|
||||
this.example = resolve('Example');
|
||||
}
|
||||
|
||||
MyConstructor.prototype = {
|
||||
protoProperty: resolve('Proto Property')
|
||||
};
|
||||
|
||||
let myObject = new MyConstructor();
|
||||
|
||||
hash(myObject).then(function(hash){
|
||||
// protoProperty will not be present, instead you will just have an
|
||||
// object that looks like:
|
||||
// {
|
||||
// example: 'Example'
|
||||
// }
|
||||
//
|
||||
// hash.hasOwnProperty('protoProperty'); // false
|
||||
// 'undefined' === typeof hash.protoProperty
|
||||
});
|
||||
```
|
||||
|
||||
@method hash
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {Object} object
|
||||
@param {String} [label] optional string that describes the promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} promise that is fulfilled when all properties of `promises`
|
||||
have been fulfilled, or rejected if any of them become rejected.
|
||||
*/
|
||||
export default function hash(object, label) {
|
||||
return Promise.resolve(object, label)
|
||||
.then(function(object) {
|
||||
if (object === null || typeof object !== 'object') {
|
||||
throw new TypeError("Promise.hash must be called with an object");
|
||||
}
|
||||
return new PromiseHash(Promise, object, label).promise;
|
||||
});
|
||||
}
|
39
node_modules/rsvp/lib/rsvp/instrument.js
generated
vendored
Normal file
39
node_modules/rsvp/lib/rsvp/instrument.js
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { config } from './config';
|
||||
|
||||
const queue = [];
|
||||
|
||||
function scheduleFlush() {
|
||||
setTimeout(() => {
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
let entry = queue[i];
|
||||
|
||||
let payload = entry.payload;
|
||||
|
||||
payload.guid = payload.key + payload.id;
|
||||
payload.childGuid = payload.key + payload.childId;
|
||||
if (payload.error) {
|
||||
payload.stack = payload.error.stack;
|
||||
}
|
||||
|
||||
config['trigger'](entry.name, entry.payload);
|
||||
}
|
||||
queue.length = 0;
|
||||
}, 50);
|
||||
}
|
||||
|
||||
export default function instrument(eventName, promise, child) {
|
||||
if (1 === queue.push({
|
||||
name: eventName,
|
||||
payload: {
|
||||
key: promise._guidKey,
|
||||
id: promise._id,
|
||||
eventName: eventName,
|
||||
detail: promise._result,
|
||||
childId: child && child._id,
|
||||
label: promise._label,
|
||||
timeStamp: Date.now(),
|
||||
error: config["instrument-with-stack"] ? new Error(promise._label) : null
|
||||
}})) {
|
||||
scheduleFlush();
|
||||
}
|
||||
}
|
132
node_modules/rsvp/lib/rsvp/map.js
generated
vendored
Normal file
132
node_modules/rsvp/lib/rsvp/map.js
generated
vendored
Normal file
|
@ -0,0 +1,132 @@
|
|||
import Promise from './promise';
|
||||
import {
|
||||
default as Enumerator
|
||||
} from './enumerator';
|
||||
import {
|
||||
REJECTED
|
||||
} from './-internal';
|
||||
|
||||
export class MapEnumerator extends Enumerator {
|
||||
constructor(Constructor, entries, mapFn, label) {
|
||||
super(Constructor, entries, true, label, mapFn);
|
||||
}
|
||||
|
||||
_init(Constructor, input, bool, label, mapFn) {
|
||||
let len = input.length || 0;
|
||||
this.length = len;
|
||||
this._remaining = len;
|
||||
this._result = new Array(len);
|
||||
this._mapFn = mapFn;
|
||||
|
||||
this._enumerate(input);
|
||||
}
|
||||
|
||||
_setResultAt(state, i, value, firstPass) {
|
||||
if (firstPass) {
|
||||
try {
|
||||
this._eachEntry(this._mapFn(value, i), i, false);
|
||||
} catch (error) {
|
||||
this._settledAt(REJECTED, i, error, false);
|
||||
}
|
||||
} else {
|
||||
this._remaining--;
|
||||
this._result[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
`map` is similar to JavaScript's native `map` method. `mapFn` is eagerly called
|
||||
meaning that as soon as any promise resolves its value will be passed to `mapFn`.
|
||||
`map` returns a promise that will become fulfilled with the result of running
|
||||
`mapFn` on the values the promises become fulfilled with.
|
||||
|
||||
For example:
|
||||
|
||||
```javascript
|
||||
import { map, resolve } from 'rsvp';
|
||||
|
||||
let promise1 = resolve(1);
|
||||
let promise2 = resolve(2);
|
||||
let promise3 = resolve(3);
|
||||
let promises = [ promise1, promise2, promise3 ];
|
||||
|
||||
let mapFn = function(item){
|
||||
return item + 1;
|
||||
};
|
||||
|
||||
map(promises, mapFn).then(function(result){
|
||||
// result is [ 2, 3, 4 ]
|
||||
});
|
||||
```
|
||||
|
||||
If any of the `promises` given to `map` are rejected, the first promise
|
||||
that is rejected will be given as an argument to the returned promise's
|
||||
rejection handler. For example:
|
||||
|
||||
```javascript
|
||||
import { map, reject, resolve } from 'rsvp';
|
||||
|
||||
let promise1 = resolve(1);
|
||||
let promise2 = reject(new Error('2'));
|
||||
let promise3 = reject(new Error('3'));
|
||||
let promises = [ promise1, promise2, promise3 ];
|
||||
|
||||
let mapFn = function(item){
|
||||
return item + 1;
|
||||
};
|
||||
|
||||
map(promises, mapFn).then(function(array){
|
||||
// Code here never runs because there are rejected promises!
|
||||
}, function(reason) {
|
||||
// reason.message === '2'
|
||||
});
|
||||
```
|
||||
|
||||
`map` will also wait if a promise is returned from `mapFn`. For example,
|
||||
say you want to get all comments from a set of blog posts, but you need
|
||||
the blog posts first because they contain a url to those comments.
|
||||
|
||||
```javscript
|
||||
import { map } from 'rsvp';
|
||||
|
||||
let mapFn = function(blogPost){
|
||||
// getComments does some ajax and returns an Promise that is fulfilled
|
||||
// with some comments data
|
||||
return getComments(blogPost.comments_url);
|
||||
};
|
||||
|
||||
// getBlogPosts does some ajax and returns an Promise that is fulfilled
|
||||
// with some blog post data
|
||||
map(getBlogPosts(), mapFn).then(function(comments){
|
||||
// comments is the result of asking the server for the comments
|
||||
// of all blog posts returned from getBlogPosts()
|
||||
});
|
||||
```
|
||||
|
||||
@method map
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {Array} promises
|
||||
@param {Function} mapFn function to be called on each fulfilled promise.
|
||||
@param {String} [label] optional string for labeling the promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} promise that is fulfilled with the result of calling
|
||||
`mapFn` on each fulfilled promise or value when they become fulfilled.
|
||||
The promise will be rejected if any of the given `promises` become rejected.
|
||||
*/
|
||||
export default function map(promises, mapFn, label) {
|
||||
if (typeof mapFn !== 'function') {
|
||||
return Promise.reject(new TypeError("map expects a function as a second argument"), label);
|
||||
}
|
||||
|
||||
return Promise.resolve(promises, label)
|
||||
.then(function(promises) {
|
||||
if (!Array.isArray(promises)) {
|
||||
throw new TypeError("map must be called with an array");
|
||||
}
|
||||
return new MapEnumerator(Promise, promises, mapFn, label).promise;
|
||||
});
|
||||
}
|
245
node_modules/rsvp/lib/rsvp/node.js
generated
vendored
Normal file
245
node_modules/rsvp/lib/rsvp/node.js
generated
vendored
Normal file
|
@ -0,0 +1,245 @@
|
|||
import Promise from './promise';
|
||||
import {
|
||||
noop,
|
||||
resolve,
|
||||
reject,
|
||||
} from './-internal';
|
||||
|
||||
function makeObject(_, argumentNames) {
|
||||
let obj = {};
|
||||
let length = _.length;
|
||||
let args = new Array(length);
|
||||
|
||||
for (let x = 0; x < length; x++) {
|
||||
args[x] = _[x];
|
||||
}
|
||||
|
||||
for (let i = 0; i < argumentNames.length; i++) {
|
||||
let name = argumentNames[i];
|
||||
obj[name] = args[i + 1];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
function arrayResult(_) {
|
||||
let length = _.length;
|
||||
let args = new Array(length - 1);
|
||||
|
||||
for (let i = 1; i < length; i++) {
|
||||
args[i - 1] = _[i];
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
function wrapThenable(then, promise) {
|
||||
return {
|
||||
then(onFulFillment, onRejection) {
|
||||
return then.call(promise, onFulFillment, onRejection);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
`denodeify` takes a 'node-style' function and returns a function that
|
||||
will return an `Promise`. You can use `denodeify` in Node.js or the
|
||||
browser when you'd prefer to use promises over using callbacks. For example,
|
||||
`denodeify` transforms the following:
|
||||
|
||||
```javascript
|
||||
let fs = require('fs');
|
||||
|
||||
fs.readFile('myfile.txt', function(err, data){
|
||||
if (err) return handleError(err);
|
||||
handleData(data);
|
||||
});
|
||||
```
|
||||
|
||||
into:
|
||||
|
||||
```javascript
|
||||
let fs = require('fs');
|
||||
let readFile = denodeify(fs.readFile);
|
||||
|
||||
readFile('myfile.txt').then(handleData, handleError);
|
||||
```
|
||||
|
||||
If the node function has multiple success parameters, then `denodeify`
|
||||
just returns the first one:
|
||||
|
||||
```javascript
|
||||
let request = denodeify(require('request'));
|
||||
|
||||
request('http://example.com').then(function(res) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
However, if you need all success parameters, setting `denodeify`'s
|
||||
second parameter to `true` causes it to return all success parameters
|
||||
as an array:
|
||||
|
||||
```javascript
|
||||
let request = denodeify(require('request'), true);
|
||||
|
||||
request('http://example.com').then(function(result) {
|
||||
// result[0] -> res
|
||||
// result[1] -> body
|
||||
});
|
||||
```
|
||||
|
||||
Or if you pass it an array with names it returns the parameters as a hash:
|
||||
|
||||
```javascript
|
||||
let request = denodeify(require('request'), ['res', 'body']);
|
||||
|
||||
request('http://example.com').then(function(result) {
|
||||
// result.res
|
||||
// result.body
|
||||
});
|
||||
```
|
||||
|
||||
Sometimes you need to retain the `this`:
|
||||
|
||||
```javascript
|
||||
let app = require('express')();
|
||||
let render = denodeify(app.render.bind(app));
|
||||
```
|
||||
|
||||
The denodified function inherits from the original function. It works in all
|
||||
environments, except IE 10 and below. Consequently all properties of the original
|
||||
function are available to you. However, any properties you change on the
|
||||
denodeified function won't be changed on the original function. Example:
|
||||
|
||||
```javascript
|
||||
let request = denodeify(require('request')),
|
||||
cookieJar = request.jar(); // <- Inheritance is used here
|
||||
|
||||
request('http://example.com', {jar: cookieJar}).then(function(res) {
|
||||
// cookieJar.cookies holds now the cookies returned by example.com
|
||||
});
|
||||
```
|
||||
|
||||
Using `denodeify` makes it easier to compose asynchronous operations instead
|
||||
of using callbacks. For example, instead of:
|
||||
|
||||
```javascript
|
||||
let fs = require('fs');
|
||||
|
||||
fs.readFile('myfile.txt', function(err, data){
|
||||
if (err) { ... } // Handle error
|
||||
fs.writeFile('myfile2.txt', data, function(err){
|
||||
if (err) { ... } // Handle error
|
||||
console.log('done')
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
you can chain the operations together using `then` from the returned promise:
|
||||
|
||||
```javascript
|
||||
let fs = require('fs');
|
||||
let readFile = denodeify(fs.readFile);
|
||||
let writeFile = denodeify(fs.writeFile);
|
||||
|
||||
readFile('myfile.txt').then(function(data){
|
||||
return writeFile('myfile2.txt', data);
|
||||
}).then(function(){
|
||||
console.log('done')
|
||||
}).catch(function(error){
|
||||
// Handle error
|
||||
});
|
||||
```
|
||||
|
||||
@method denodeify
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {Function} nodeFunc a 'node-style' function that takes a callback as
|
||||
its last argument. The callback expects an error to be passed as its first
|
||||
argument (if an error occurred, otherwise null), and the value from the
|
||||
operation as its second argument ('function(err, value){ }').
|
||||
@param {Boolean|Array} [options] An optional paramter that if set
|
||||
to `true` causes the promise to fulfill with the callback's success arguments
|
||||
as an array. This is useful if the node function has multiple success
|
||||
paramters. If you set this paramter to an array with names, the promise will
|
||||
fulfill with a hash with these names as keys and the success parameters as
|
||||
values.
|
||||
@return {Function} a function that wraps `nodeFunc` to return a `Promise`
|
||||
*/
|
||||
export default function denodeify(nodeFunc, options) {
|
||||
let fn = function() {
|
||||
let l = arguments.length;
|
||||
let args = new Array(l + 1);
|
||||
let promiseInput = false;
|
||||
|
||||
for (let i = 0; i < l; ++i) {
|
||||
let arg = arguments[i];
|
||||
let then;
|
||||
|
||||
// TODO: this code really needs to be cleaned up
|
||||
if (!promiseInput) {
|
||||
if (arg !== null && typeof arg === 'object') {
|
||||
if (arg.constructor === Promise) {
|
||||
promiseInput = true;
|
||||
} else {
|
||||
try {
|
||||
promiseInput = arg.then;
|
||||
} catch(error) {
|
||||
let p = new Promise(noop);
|
||||
reject(p, error);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
promiseInput = false;
|
||||
}
|
||||
if (promiseInput && promiseInput !== true) {
|
||||
arg = wrapThenable(promiseInput, arg);
|
||||
}
|
||||
}
|
||||
args[i] = arg;
|
||||
}
|
||||
|
||||
let promise = new Promise(noop);
|
||||
|
||||
args[l] = function(err, val) {
|
||||
if (err) {
|
||||
reject(promise, err);
|
||||
} else if (options === undefined) {
|
||||
resolve(promise, val);
|
||||
} else if (options === true) {
|
||||
resolve(promise, arrayResult(arguments));
|
||||
} else if (Array.isArray(options)) {
|
||||
resolve(promise, makeObject(arguments, options));
|
||||
} else {
|
||||
resolve(promise, val);
|
||||
}
|
||||
};
|
||||
|
||||
if (promiseInput) {
|
||||
return handlePromiseInput(promise, args, nodeFunc, this);
|
||||
} else {
|
||||
return handleValueInput(promise, args, nodeFunc, this);
|
||||
}
|
||||
};
|
||||
|
||||
fn.__proto__ = nodeFunc;
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
function handleValueInput(promise, args, nodeFunc, self) {
|
||||
try {
|
||||
nodeFunc.apply(self, args);
|
||||
} catch (error) {
|
||||
reject(promise, error);
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
||||
function handlePromiseInput(promise, args, nodeFunc, self){
|
||||
return Promise.all(args)
|
||||
.then(args => handleValueInput(promise, args, nodeFunc, self));
|
||||
}
|
34
node_modules/rsvp/lib/rsvp/promise-hash.js
generated
vendored
Normal file
34
node_modules/rsvp/lib/rsvp/promise-hash.js
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
import Enumerator from './enumerator';
|
||||
import {
|
||||
PENDING,
|
||||
FULFILLED,
|
||||
fulfill
|
||||
} from './-internal';
|
||||
|
||||
export default class PromiseHash extends Enumerator {
|
||||
constructor(Constructor, object, abortOnReject = true, label) {
|
||||
super(Constructor, object, abortOnReject, label);
|
||||
}
|
||||
|
||||
_init(Constructor, object) {
|
||||
this._result = {};
|
||||
this._enumerate(object);
|
||||
}
|
||||
|
||||
_enumerate(input) {
|
||||
let keys = Object.keys(input);
|
||||
|
||||
let length = keys.length;
|
||||
let promise = this.promise;
|
||||
this._remaining = length;
|
||||
|
||||
let key, val;
|
||||
for (let i = 0; promise._state === PENDING && i < length; i++) {
|
||||
key = keys[i];
|
||||
val = input[key];
|
||||
this._eachEntry(val, key, true);
|
||||
}
|
||||
|
||||
this._checkFullfillment();
|
||||
}
|
||||
}
|
444
node_modules/rsvp/lib/rsvp/promise.js
generated
vendored
Normal file
444
node_modules/rsvp/lib/rsvp/promise.js
generated
vendored
Normal file
|
@ -0,0 +1,444 @@
|
|||
import { config } from './config';
|
||||
import instrument from './instrument';
|
||||
import then from './then';
|
||||
|
||||
import {
|
||||
noop,
|
||||
initializePromise
|
||||
} from './-internal';
|
||||
|
||||
import all from './promise/all';
|
||||
import race from './promise/race';
|
||||
import Resolve from './promise/resolve';
|
||||
import Reject from './promise/reject';
|
||||
|
||||
const guidKey = 'rsvp_' + Date.now() + '-';
|
||||
let counter = 0;
|
||||
|
||||
function needsResolver() {
|
||||
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
||||
}
|
||||
|
||||
function needsNew() {
|
||||
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
||||
}
|
||||
|
||||
/**
|
||||
Promise objects represent the eventual result of an asynchronous operation. The
|
||||
primary way of interacting with a promise is through its `then` method, which
|
||||
registers callbacks to receive either a promise’s eventual value or the reason
|
||||
why the promise cannot be fulfilled.
|
||||
|
||||
Terminology
|
||||
-----------
|
||||
|
||||
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
||||
- `thenable` is an object or function that defines a `then` method.
|
||||
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
||||
- `exception` is a value that is thrown using the throw statement.
|
||||
- `reason` is a value that indicates why a promise was rejected.
|
||||
- `settled` the final resting state of a promise, fulfilled or rejected.
|
||||
|
||||
A promise can be in one of three states: pending, fulfilled, or rejected.
|
||||
|
||||
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
||||
state. Promises that are rejected have a rejection reason and are in the
|
||||
rejected state. A fulfillment value is never a thenable.
|
||||
|
||||
Promises can also be said to *resolve* a value. If this value is also a
|
||||
promise, then the original promise's settled state will match the value's
|
||||
settled state. So a promise that *resolves* a promise that rejects will
|
||||
itself reject, and a promise that *resolves* a promise that fulfills will
|
||||
itself fulfill.
|
||||
|
||||
|
||||
Basic Usage:
|
||||
------------
|
||||
|
||||
```js
|
||||
let promise = new Promise(function(resolve, reject) {
|
||||
// on success
|
||||
resolve(value);
|
||||
|
||||
// on failure
|
||||
reject(reason);
|
||||
});
|
||||
|
||||
promise.then(function(value) {
|
||||
// on fulfillment
|
||||
}, function(reason) {
|
||||
// on rejection
|
||||
});
|
||||
```
|
||||
|
||||
Advanced Usage:
|
||||
---------------
|
||||
|
||||
Promises shine when abstracting away asynchronous interactions such as
|
||||
`XMLHttpRequest`s.
|
||||
|
||||
```js
|
||||
function getJSON(url) {
|
||||
return new Promise(function(resolve, reject){
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', url);
|
||||
xhr.onreadystatechange = handler;
|
||||
xhr.responseType = 'json';
|
||||
xhr.setRequestHeader('Accept', 'application/json');
|
||||
xhr.send();
|
||||
|
||||
function handler() {
|
||||
if (this.readyState === this.DONE) {
|
||||
if (this.status === 200) {
|
||||
resolve(this.response);
|
||||
} else {
|
||||
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
getJSON('/posts.json').then(function(json) {
|
||||
// on fulfillment
|
||||
}, function(reason) {
|
||||
// on rejection
|
||||
});
|
||||
```
|
||||
|
||||
Unlike callbacks, promises are great composable primitives.
|
||||
|
||||
```js
|
||||
Promise.all([
|
||||
getJSON('/posts'),
|
||||
getJSON('/comments')
|
||||
]).then(function(values){
|
||||
values[0] // => postsJSON
|
||||
values[1] // => commentsJSON
|
||||
|
||||
return values;
|
||||
});
|
||||
```
|
||||
|
||||
@class Promise
|
||||
@public
|
||||
@param {function} resolver
|
||||
@param {String} [label] optional string for labeling the promise.
|
||||
Useful for tooling.
|
||||
@constructor
|
||||
*/
|
||||
class Promise {
|
||||
constructor(resolver, label) {
|
||||
this._id = counter++;
|
||||
this._label = label;
|
||||
this._state = undefined;
|
||||
this._result = undefined;
|
||||
this._subscribers = [];
|
||||
|
||||
config.instrument && instrument('created', this);
|
||||
|
||||
if (noop !== resolver) {
|
||||
typeof resolver !== 'function' && needsResolver();
|
||||
this instanceof Promise ? initializePromise(this, resolver) : needsNew();
|
||||
}
|
||||
}
|
||||
|
||||
_onError(reason) {
|
||||
config.after(() => {
|
||||
if (this._onError) {
|
||||
config.trigger('error', reason, this._label);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
||||
as the catch block of a try/catch statement.
|
||||
|
||||
```js
|
||||
function findAuthor(){
|
||||
throw new Error('couldn\'t find that author');
|
||||
}
|
||||
|
||||
// synchronous
|
||||
try {
|
||||
findAuthor();
|
||||
} catch(reason) {
|
||||
// something went wrong
|
||||
}
|
||||
|
||||
// async with promises
|
||||
findAuthor().catch(function(reason){
|
||||
// something went wrong
|
||||
});
|
||||
```
|
||||
|
||||
@method catch
|
||||
@param {Function} onRejection
|
||||
@param {String} [label] optional string for labeling the promise.
|
||||
Useful for tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
catch(onRejection, label) {
|
||||
return this.then(undefined, onRejection, label);
|
||||
}
|
||||
|
||||
/**
|
||||
`finally` will be invoked regardless of the promise's fate just as native
|
||||
try/catch/finally behaves
|
||||
|
||||
Synchronous example:
|
||||
|
||||
```js
|
||||
findAuthor() {
|
||||
if (Math.random() > 0.5) {
|
||||
throw new Error();
|
||||
}
|
||||
return new Author();
|
||||
}
|
||||
|
||||
try {
|
||||
return findAuthor(); // succeed or fail
|
||||
} catch(error) {
|
||||
return findOtherAuthor();
|
||||
} finally {
|
||||
// always runs
|
||||
// doesn't affect the return value
|
||||
}
|
||||
```
|
||||
|
||||
Asynchronous example:
|
||||
|
||||
```js
|
||||
findAuthor().catch(function(reason){
|
||||
return findOtherAuthor();
|
||||
}).finally(function(){
|
||||
// author was either found, or not
|
||||
});
|
||||
```
|
||||
|
||||
@method finally
|
||||
@param {Function} callback
|
||||
@param {String} [label] optional string for labeling the promise.
|
||||
Useful for tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
finally(callback, label) {
|
||||
let promise = this;
|
||||
let constructor = promise.constructor;
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
return promise.then(value => constructor.resolve(callback()).then(() => value),
|
||||
reason => constructor.resolve(callback()).then(() => { throw reason; }));
|
||||
}
|
||||
|
||||
return promise.then(callback, callback);
|
||||
}
|
||||
}
|
||||
|
||||
Promise.cast = Resolve; // deprecated
|
||||
Promise.all = all;
|
||||
Promise.race = race;
|
||||
Promise.resolve = Resolve;
|
||||
Promise.reject = Reject;
|
||||
|
||||
Promise.prototype._guidKey = guidKey;
|
||||
|
||||
/**
|
||||
The primary way of interacting with a promise is through its `then` method,
|
||||
which registers callbacks to receive either a promise's eventual value or the
|
||||
reason why the promise cannot be fulfilled.
|
||||
|
||||
```js
|
||||
findUser().then(function(user){
|
||||
// user is available
|
||||
}, function(reason){
|
||||
// user is unavailable, and you are given the reason why
|
||||
});
|
||||
```
|
||||
|
||||
Chaining
|
||||
--------
|
||||
|
||||
The return value of `then` is itself a promise. This second, 'downstream'
|
||||
promise is resolved with the return value of the first promise's fulfillment
|
||||
or rejection handler, or rejected if the handler throws an exception.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return user.name;
|
||||
}, function (reason) {
|
||||
return 'default name';
|
||||
}).then(function (userName) {
|
||||
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
||||
// will be `'default name'`
|
||||
});
|
||||
|
||||
findUser().then(function (user) {
|
||||
throw new Error('Found user, but still unhappy');
|
||||
}, function (reason) {
|
||||
throw new Error('`findUser` rejected and we\'re unhappy');
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}, function (reason) {
|
||||
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
||||
// If `findUser` rejected, `reason` will be '`findUser` rejected and we\'re unhappy'.
|
||||
});
|
||||
```
|
||||
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
throw new PedagogicalException('Upstream error');
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}).then(function (value) {
|
||||
// never reached
|
||||
}, function (reason) {
|
||||
// The `PedgagocialException` is propagated all the way down to here
|
||||
});
|
||||
```
|
||||
|
||||
Assimilation
|
||||
------------
|
||||
|
||||
Sometimes the value you want to propagate to a downstream promise can only be
|
||||
retrieved asynchronously. This can be achieved by returning a promise in the
|
||||
fulfillment or rejection handler. The downstream promise will then be pending
|
||||
until the returned promise is settled. This is called *assimilation*.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return findCommentsByAuthor(user);
|
||||
}).then(function (comments) {
|
||||
// The user's comments are now available
|
||||
});
|
||||
```
|
||||
|
||||
If the assimliated promise rejects, then the downstream promise will also reject.
|
||||
|
||||
```js
|
||||
findUser().then(function (user) {
|
||||
return findCommentsByAuthor(user);
|
||||
}).then(function (comments) {
|
||||
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
||||
}, function (reason) {
|
||||
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
||||
});
|
||||
```
|
||||
|
||||
Simple Example
|
||||
--------------
|
||||
|
||||
Synchronous Example
|
||||
|
||||
```javascript
|
||||
let result;
|
||||
|
||||
try {
|
||||
result = findResult();
|
||||
// success
|
||||
} catch(reason) {
|
||||
// failure
|
||||
}
|
||||
```
|
||||
|
||||
Errback Example
|
||||
|
||||
```js
|
||||
findResult(function(result, err){
|
||||
if (err) {
|
||||
// failure
|
||||
} else {
|
||||
// success
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Promise Example;
|
||||
|
||||
```javascript
|
||||
findResult().then(function(result){
|
||||
// success
|
||||
}, function(reason){
|
||||
// failure
|
||||
});
|
||||
```
|
||||
|
||||
Advanced Example
|
||||
--------------
|
||||
|
||||
Synchronous Example
|
||||
|
||||
```javascript
|
||||
let author, books;
|
||||
|
||||
try {
|
||||
author = findAuthor();
|
||||
books = findBooksByAuthor(author);
|
||||
// success
|
||||
} catch(reason) {
|
||||
// failure
|
||||
}
|
||||
```
|
||||
|
||||
Errback Example
|
||||
|
||||
```js
|
||||
|
||||
function foundBooks(books) {
|
||||
|
||||
}
|
||||
|
||||
function failure(reason) {
|
||||
|
||||
}
|
||||
|
||||
findAuthor(function(author, err){
|
||||
if (err) {
|
||||
failure(err);
|
||||
// failure
|
||||
} else {
|
||||
try {
|
||||
findBoooksByAuthor(author, function(books, err) {
|
||||
if (err) {
|
||||
failure(err);
|
||||
} else {
|
||||
try {
|
||||
foundBooks(books);
|
||||
} catch(reason) {
|
||||
failure(reason);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(error) {
|
||||
failure(err);
|
||||
}
|
||||
// success
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Promise Example;
|
||||
|
||||
```javascript
|
||||
findAuthor().
|
||||
then(findBooksByAuthor).
|
||||
then(function(books){
|
||||
// found books
|
||||
}).catch(function(reason){
|
||||
// something went wrong
|
||||
});
|
||||
```
|
||||
|
||||
@method then
|
||||
@param {Function} onFulfillment
|
||||
@param {Function} onRejection
|
||||
@param {String} [label] optional string for labeling the promise.
|
||||
Useful for tooling.
|
||||
@return {Promise}
|
||||
*/
|
||||
Promise.prototype.then = then;
|
||||
|
||||
export default Promise;
|
59
node_modules/rsvp/lib/rsvp/promise/all.js
generated
vendored
Normal file
59
node_modules/rsvp/lib/rsvp/promise/all.js
generated
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
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
|
||||
import Promise, { resolve } from 'rsvp';
|
||||
|
||||
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 `RSVP.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
|
||||
import Promise, { resolve, reject } from 'rsvp';
|
||||
|
||||
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
|
||||
@for Promise
|
||||
@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, label) {
|
||||
if (!Array.isArray(entries)) {
|
||||
return this.reject(new TypeError("Promise.all must be called with an array"), label);
|
||||
}
|
||||
return new Enumerator(this, entries, true /* abort on reject */, label).promise;
|
||||
}
|
102
node_modules/rsvp/lib/rsvp/promise/race.js
generated
vendored
Normal file
102
node_modules/rsvp/lib/rsvp/promise/race.js
generated
vendored
Normal file
|
@ -0,0 +1,102 @@
|
|||
import {
|
||||
noop,
|
||||
resolve,
|
||||
reject,
|
||||
subscribe,
|
||||
PENDING
|
||||
} from '../-internal';
|
||||
|
||||
/**
|
||||
`Promise.race` returns a new promise which is settled in the same way as the
|
||||
first passed promise to settle.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
import Promise from 'rsvp';
|
||||
|
||||
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
|
||||
import Promise from 'rsvp';
|
||||
|
||||
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
|
||||
import Promise from 'rsvp';
|
||||
|
||||
Promise.race([ajax('foo.json'), timeout(5000)])
|
||||
```
|
||||
|
||||
@method race
|
||||
@for Promise
|
||||
@static
|
||||
@param {Array} entries array of promises to observe
|
||||
@param {String} [label] optional string for describing the promise returned.
|
||||
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, label) {
|
||||
/*jshint validthis:true */
|
||||
let Constructor = this;
|
||||
|
||||
let promise = new Constructor(noop, label);
|
||||
|
||||
if (!Array.isArray(entries)) {
|
||||
reject(promise, new TypeError('Promise.race must be called with an array'));
|
||||
return promise;
|
||||
}
|
||||
|
||||
for (let i = 0; promise._state === PENDING && i < entries.length; i++) {
|
||||
subscribe(
|
||||
Constructor.resolve(entries[i]), undefined,
|
||||
value => resolve(promise, value),
|
||||
reason => reject(promise, reason)
|
||||
);
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
52
node_modules/rsvp/lib/rsvp/promise/reject.js
generated
vendored
Normal file
52
node_modules/rsvp/lib/rsvp/promise/reject.js
generated
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
import {
|
||||
noop,
|
||||
reject as _reject
|
||||
} from '../-internal';
|
||||
|
||||
/**
|
||||
`Promise.reject` returns a promise rejected with the passed `reason`.
|
||||
It is shorthand for the following:
|
||||
|
||||
```javascript
|
||||
import Promise from 'rsvp';
|
||||
|
||||
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
|
||||
import Promise from 'rsvp';
|
||||
|
||||
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
|
||||
@for Promise
|
||||
@static
|
||||
@param {*} reason value that the returned promise will be rejected with.
|
||||
@param {String} [label] optional string for identifying the returned promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise rejected with the given `reason`.
|
||||
*/
|
||||
export default function reject(reason, label) {
|
||||
/*jshint validthis:true */
|
||||
let Constructor = this;
|
||||
let promise = new Constructor(noop, label);
|
||||
_reject(promise, reason);
|
||||
return promise;
|
||||
}
|
54
node_modules/rsvp/lib/rsvp/promise/resolve.js
generated
vendored
Normal file
54
node_modules/rsvp/lib/rsvp/promise/resolve.js
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
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
|
||||
import Promise from 'rsvp';
|
||||
|
||||
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
|
||||
import Promise from 'rsvp';
|
||||
|
||||
let promise = RSVP.Promise.resolve(1);
|
||||
|
||||
promise.then(function(value){
|
||||
// value === 1
|
||||
});
|
||||
```
|
||||
|
||||
@method resolve
|
||||
@for Promise
|
||||
@static
|
||||
@param {*} object value that the returned promise will be resolved with
|
||||
@param {String} [label] optional string for identifying the returned promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise that will become fulfilled with the given
|
||||
`value`
|
||||
*/
|
||||
export default function resolve(object, label) {
|
||||
/*jshint validthis:true */
|
||||
let Constructor = this;
|
||||
|
||||
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
||||
return object;
|
||||
}
|
||||
|
||||
let promise = new Constructor(noop, label);
|
||||
_resolve(promise, object);
|
||||
return promise;
|
||||
}
|
16
node_modules/rsvp/lib/rsvp/race.js
generated
vendored
Normal file
16
node_modules/rsvp/lib/rsvp/race.js
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
import Promise from './promise';
|
||||
|
||||
/**
|
||||
This is a convenient alias for `Promise.race`.
|
||||
|
||||
@method race
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {Array} array Array of promises.
|
||||
@param {String} [label] An optional label. This is useful
|
||||
for tooling.
|
||||
*/
|
||||
export default function race(array, label) {
|
||||
return Promise.race(array, label);
|
||||
}
|
17
node_modules/rsvp/lib/rsvp/reject.js
generated
vendored
Normal file
17
node_modules/rsvp/lib/rsvp/reject.js
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
import Promise from './promise';
|
||||
|
||||
/**
|
||||
This is a convenient alias for `Promise.reject`.
|
||||
|
||||
@method reject
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {*} reason value that the returned promise will be rejected with.
|
||||
@param {String} [label] optional string for identifying the returned promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise rejected with the given `reason`.
|
||||
*/
|
||||
export default function reject(reason, label) {
|
||||
return Promise.reject(reason, label);
|
||||
}
|
18
node_modules/rsvp/lib/rsvp/resolve.js
generated
vendored
Normal file
18
node_modules/rsvp/lib/rsvp/resolve.js
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
import Promise from './promise';
|
||||
|
||||
/**
|
||||
This is a convenient alias for `Promise.resolve`.
|
||||
|
||||
@method resolve
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {*} value value that the returned promise will be resolved with
|
||||
@param {String} [label] optional string for identifying the returned promise.
|
||||
Useful for tooling.
|
||||
@return {Promise} a promise that will become fulfilled with the given
|
||||
`value`
|
||||
*/
|
||||
export default function resolve(value, label) {
|
||||
return Promise.resolve(value, label);
|
||||
}
|
49
node_modules/rsvp/lib/rsvp/rethrow.js
generated
vendored
Normal file
49
node_modules/rsvp/lib/rsvp/rethrow.js
generated
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
`rethrow` will rethrow an error on the next turn of the JavaScript event
|
||||
loop in order to aid debugging.
|
||||
|
||||
Promises A+ specifies that any exceptions that occur with a promise must be
|
||||
caught by the promises implementation and bubbled to the last handler. For
|
||||
this reason, it is recommended that you always specify a second rejection
|
||||
handler function to `then`. However, `rethrow` will throw the exception
|
||||
outside of the promise, so it bubbles up to your console if in the browser,
|
||||
or domain/cause uncaught exception in Node. `rethrow` will also throw the
|
||||
error again so the error can be handled by the promise per the spec.
|
||||
|
||||
```javascript
|
||||
import { rethrow } from 'rsvp';
|
||||
|
||||
function throws(){
|
||||
throw new Error('Whoops!');
|
||||
}
|
||||
|
||||
let promise = new Promise(function(resolve, reject){
|
||||
throws();
|
||||
});
|
||||
|
||||
promise.catch(rethrow).then(function(){
|
||||
// Code here doesn't run because the promise became rejected due to an
|
||||
// error!
|
||||
}, function (err){
|
||||
// handle the error here
|
||||
});
|
||||
```
|
||||
|
||||
The 'Whoops' error will be thrown on the next turn of the event loop
|
||||
and you can watch for it in your console. You can also handle it using a
|
||||
rejection handler given to `.then` or `.catch` on the returned promise.
|
||||
|
||||
@method rethrow
|
||||
@public
|
||||
@static
|
||||
@for rsvp
|
||||
@param {Error} reason reason the promise became rejected.
|
||||
@throws Error
|
||||
@static
|
||||
*/
|
||||
export default function rethrow(reason) {
|
||||
setTimeout(() => {
|
||||
throw reason;
|
||||
});
|
||||
throw reason;
|
||||
}
|
36
node_modules/rsvp/lib/rsvp/then.js
generated
vendored
Normal file
36
node_modules/rsvp/lib/rsvp/then.js
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { config } from './config';
|
||||
import instrument from './instrument';
|
||||
import {
|
||||
noop,
|
||||
subscribe,
|
||||
FULFILLED,
|
||||
REJECTED,
|
||||
PENDING,
|
||||
invokeCallback
|
||||
} from './-internal';
|
||||
|
||||
export default function then(onFulfillment, onRejection, label) {
|
||||
let parent = this;
|
||||
let state = parent._state;
|
||||
|
||||
if (state === FULFILLED && !onFulfillment || state === REJECTED && !onRejection) {
|
||||
config.instrument && instrument('chained', parent, parent);
|
||||
return parent;
|
||||
}
|
||||
|
||||
parent._onError = null;
|
||||
|
||||
let child = new parent.constructor(noop, label);
|
||||
let result = parent._result;
|
||||
|
||||
config.instrument && instrument('chained', parent, child);
|
||||
|
||||
if (state === PENDING) {
|
||||
subscribe(parent, child, onFulfillment, onRejection);
|
||||
} else {
|
||||
let callback = state === FULFILLED ? onFulfillment : onRejection;
|
||||
config.async(() => invokeCallback(state, child, callback, result));
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
101
node_modules/rsvp/package.json
generated
vendored
Normal file
101
node_modules/rsvp/package.json
generated
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
{
|
||||
"_from": "rsvp@^4.8.4",
|
||||
"_id": "rsvp@4.8.5",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==",
|
||||
"_location": "/rsvp",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "rsvp@^4.8.4",
|
||||
"name": "rsvp",
|
||||
"escapedName": "rsvp",
|
||||
"rawSpec": "^4.8.4",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^4.8.4"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/capture-exit"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz",
|
||||
"_shasum": "c8f155311d167f68f21e168df71ec5b083113734",
|
||||
"_spec": "rsvp@^4.8.4",
|
||||
"_where": "E:\\github\\setup-java\\node_modules\\capture-exit",
|
||||
"author": {
|
||||
"name": "Tilde, Inc. & Stefan Penner"
|
||||
},
|
||||
"browser": {
|
||||
"vertx": false
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/tildeio/rsvp.js/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "A lightweight library that provides tools for organizing asynchronous code",
|
||||
"devDependencies": {
|
||||
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
|
||||
"babel-plugin-transform-es2015-block-scoping": "6.26.0",
|
||||
"babel-plugin-transform-es2015-classes": "^6.24.1",
|
||||
"babel-plugin-transform-es2015-computed-properties": "^6.24.1",
|
||||
"babel-plugin-transform-es2015-constants": "^6.1.4",
|
||||
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
|
||||
"babel-plugin-transform-es2015-parameters": "^6.24.1",
|
||||
"babel-plugin-transform-es2015-shorthand-properties": "^6.24.1",
|
||||
"babel-plugin-transform-es2015-spread": "^6.22.0",
|
||||
"babel-plugin-transform-es2015-template-literals": "^6.22.0",
|
||||
"babel-preset-env": "1.7.0",
|
||||
"babel6-plugin-strip-class-callcheck": "^6.0.0",
|
||||
"broccoli-babel-transpiler": "6.4.3",
|
||||
"broccoli-concat": "^3.7.1",
|
||||
"broccoli-funnel": "2.0.1",
|
||||
"broccoli-merge-trees": "^3.0.1",
|
||||
"broccoli-rollup": "2.1.1",
|
||||
"broccoli-stew": "^2.0.0",
|
||||
"broccoli-uglify-js": "^0.2.0",
|
||||
"broccoli-watchify": "1.0.1",
|
||||
"ember-cli": "3.4.2",
|
||||
"ember-cli-dependency-checker": "3.0.0",
|
||||
"ember-cli-inject-live-reload": "^2.0.1",
|
||||
"ember-cli-progress": "^1.0.6",
|
||||
"git-repo-version": "1.0.2",
|
||||
"mocha": "5.2.0",
|
||||
"promises-aplus-tests": "2.1.2"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "lib"
|
||||
},
|
||||
"engines": {
|
||||
"node": "6.* || >= 7.*"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"lib",
|
||||
"!dist/test"
|
||||
],
|
||||
"homepage": "https://github.com/tildeio/rsvp.js",
|
||||
"jsnext:main": "dist/rsvp.es.js",
|
||||
"keywords": [
|
||||
"futures",
|
||||
"promises"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "dist/rsvp.js",
|
||||
"module": "dist/rsvp.es.js",
|
||||
"name": "rsvp",
|
||||
"namespace": "RSVP",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tildeio/rsvp.js.git",
|
||||
"dist": "git@github.com:components/rsvp.js.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "ember build --environment production",
|
||||
"start": "ember s",
|
||||
"test": "ember test",
|
||||
"test:node": "ember test --launch Mocha",
|
||||
"test:server": "ember test --server"
|
||||
},
|
||||
"version": "4.8.5"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue