2017-01-17 14:28:28 +00:00
|
|
|
"use strict";
|
2017-07-06 12:10:18 +00:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2017-01-17 14:28:28 +00:00
|
|
|
require("typings-global");
|
2017-07-06 12:10:18 +00:00
|
|
|
const util = require("util");
|
2017-01-17 14:28:28 +00:00
|
|
|
class Deferred {
|
|
|
|
constructor() {
|
|
|
|
this.promise = new Promise((resolve, reject) => {
|
|
|
|
this.resolve = resolve;
|
|
|
|
this.reject = reject;
|
2017-07-27 16:17:37 +00:00
|
|
|
this.status = 'pending';
|
2017-01-17 14:28:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.Deferred = Deferred;
|
|
|
|
exports.defer = () => {
|
|
|
|
return new Deferred();
|
|
|
|
};
|
2017-01-20 20:58:53 +00:00
|
|
|
/**
|
|
|
|
* Creates a new resolved promise for the provided value.
|
|
|
|
*/
|
2017-01-20 23:45:11 +00:00
|
|
|
exports.resolvedPromise = (value) => {
|
|
|
|
return Promise.resolve(value);
|
|
|
|
};
|
2017-01-20 20:58:53 +00:00
|
|
|
/**
|
|
|
|
* Creates a new rejected promise for the provided reason.
|
|
|
|
*/
|
2017-01-20 23:45:11 +00:00
|
|
|
exports.rejectedPromise = (err) => {
|
|
|
|
return Promise.reject(err);
|
|
|
|
};
|
2017-07-06 12:10:18 +00:00
|
|
|
exports.promisify = util.promisify;
|
2017-07-06 12:55:42 +00:00
|
|
|
// polyfill
|
|
|
|
if (!exports.promisify) {
|
|
|
|
exports.promisify = require('util.promisify');
|
|
|
|
}
|
2017-07-06 12:10:18 +00:00
|
|
|
exports.map = (inputArg, functionArg) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
let promisifedFunction = exports.promisify(functionArg);
|
|
|
|
let promiseArray = [];
|
|
|
|
let resultArray = [];
|
|
|
|
for (let item of inputArg) {
|
|
|
|
let promise = promisifedFunction(item);
|
|
|
|
promiseArray.push(promise);
|
|
|
|
promise.then(x => {
|
|
|
|
resultArray.push(x);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
yield Promise.all(promiseArray);
|
|
|
|
return resultArray;
|
|
|
|
});
|
2017-07-27 16:17:37 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsMEJBQXVCO0FBQ3ZCLDZCQUE0QjtBQVk1QjtJQUtFO1FBQ0UsSUFBSSxDQUFDLE9BQU8sR0FBRyxJQUFJLE9BQU8sQ0FBSSxDQUFDLE9BQU8sRUFBRSxNQUFNO1lBQzVDLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFBO1lBQ3RCLElBQUksQ0FBQyxNQUFNLEdBQUcsTUFBTSxDQUFBO1lBQ3BCLElBQUksQ0FBQyxNQUFNLEdBQUcsU0FBUyxDQUFBO1FBQ3pCLENBQUMsQ0FBQyxDQUFBO0lBQ0osQ0FBQztDQUNGO0FBWkQsNEJBWUM7QUFFVSxRQUFBLEtBQUssR0FBRztJQUNqQixNQUFNLENBQUMsSUFBSSxRQUFRLEVBQUssQ0FBQTtBQUMxQixDQUFDLENBQUE7QUFFRDs7R0FFRztBQUNRLFFBQUEsZUFBZSxHQUFHLENBQ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