@webex/common
Version:
Common utilities for Cisco Webex
45 lines (41 loc) • 1.66 kB
JavaScript
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
_Object$defineProperty(exports, "__esModule", {
value: true
});
exports.default = whileInFlight;
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
var _apply = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/apply"));
var _lodash = require("lodash");
var _tap = _interopRequireDefault(require("./tap"));
/*!
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
*/
/* eslint no-invalid-this: [0] */
/**
* While the promise returned by the decorated is unfullfilled, sets, the
* specified boolean on the target class to `true`
* @param {string} param
* @returns {Function}
*/
function whileInFlight(param) {
return function whileInFlightDecorator(target, name, descriptor) {
descriptor.value = (0, _lodash.wrap)(descriptor.value, function whileInFlightExecutor(fn) {
var _this = this;
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return new _promise.default(function (resolve) {
_this[param] = true;
resolve((0, _apply.default)(fn, _this, args).then((0, _tap.default)(function () {
_this[param] = false;
})).catch(function (reason) {
_this[param] = false;
return _promise.default.reject(reason);
}));
});
});
};
}
//# sourceMappingURL=while-in-flight.js.map
;