2015-04-15 13:04:42 +00:00
|
|
|
/**
|
|
|
|
*
|
2016-02-11 10:44:24 +00:00
|
|
|
* Copyright 2013-2014 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-04-15 13:04:42 +00:00
|
|
|
*
|
|
|
|
* @providesModule Promise
|
2016-02-11 10:44:24 +00:00
|
|
|
*
|
|
|
|
* This module wraps and augments the minimally ES6-compliant Promise
|
|
|
|
* implementation provided by the promise npm package.
|
2015-04-15 13:04:42 +00:00
|
|
|
*/
|
|
|
|
|
2016-02-11 10:44:24 +00:00
|
|
|
'use strict';
|
2016-02-11 10:20:59 +00:00
|
|
|
|
2016-02-11 10:44:24 +00:00
|
|
|
global.setImmediate = require('setImmediate');
|
|
|
|
var Promise = require('promise/setimmediate/es6-extensions');
|
|
|
|
require('promise/setimmediate/done');
|
2016-01-07 17:30:14 +00:00
|
|
|
if (__DEV__) {
|
|
|
|
require('promise/setimmediate/rejection-tracking').enable({
|
|
|
|
allRejections: true,
|
|
|
|
onUnhandled: (id, error) => {
|
|
|
|
const {message, stack} = error;
|
|
|
|
const warning =
|
|
|
|
`Possible Unhandled Promise Rejection (id: ${id}):\n` +
|
|
|
|
(message == null ? '' : `${message}\n`) +
|
|
|
|
(stack == null ? '' : stack);
|
|
|
|
console.warn(warning);
|
|
|
|
},
|
|
|
|
onHandled: (id) => {
|
|
|
|
const warning =
|
|
|
|
`Promise Rejection Handled (id: ${id})\n` +
|
|
|
|
'This means you can ignore any previous messages of the form ' +
|
|
|
|
`"Possible Unhandled Promise Rejection (id: ${id}):"`;
|
|
|
|
console.warn(warning);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2015-04-15 13:04:42 +00:00
|
|
|
|
2016-02-11 10:44:24 +00:00
|
|
|
/**
|
|
|
|
* Handle either fulfillment or rejection with the same callback.
|
|
|
|
*/
|
|
|
|
Promise.prototype.finally = function(onSettled) {
|
|
|
|
return this.then(onSettled, onSettled);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-04-15 13:04:42 +00:00
|
|
|
module.exports = Promise;
|