Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/re-executable-promise.js

41 lines
5.4 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// TODO: Fix https://github.com/DevExpress/testcafe/issues/4139 to get rid of Pinkie
const pinkie_1 = __importDefault(require("pinkie"));
const lodash_1 = require("lodash");
const test_run_tracker_1 = __importDefault(require("../api/test-run-tracker"));
class ReExecutablePromise extends pinkie_1.default {
constructor(executorFn) {
super(lodash_1.noop);
this._fn = executorFn;
this._taskPromise = null;
}
_ensureExecuting() {
if (!this._taskPromise)
this._taskPromise = new pinkie_1.default(this._fn);
}
_reExecute() {
this._taskPromise = null;
return this;
}
then(onFulfilled, onRejected) {
this._ensureExecuting();
return this._taskPromise.then(onFulfilled, onRejected);
}
catch(onRejected) {
this._ensureExecuting();
return this._taskPromise.catch(onRejected);
}
static fromFn(asyncExecutorFn) {
const testRunId = test_run_tracker_1.default.getContextTestRunId();
if (testRunId)
asyncExecutorFn = test_run_tracker_1.default.addTrackingMarkerToFunction(testRunId, asyncExecutorFn);
return new ReExecutablePromise((resolve) => resolve(asyncExecutorFn()));
}
}
exports.default = ReExecutablePromise;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmUtZXhlY3V0YWJsZS1wcm9taXNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL3JlLWV4ZWN1dGFibGUtcHJvbWlzZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLG9GQUFvRjtBQUNwRixvREFBNkI7QUFDN0IsbUNBQThCO0FBQzlCLCtFQUFxRDtBQU1yRCxNQUFxQixtQkFBb0IsU0FBUSxnQkFBZ0I7SUFJN0QsWUFBb0IsVUFBc0I7UUFDdEMsS0FBS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