Repository URL to install this package:
Version:
2.0.11-8 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function asyncThrottle(fn) {
let runningPromise;
let queuedPromise;
let nextArgs;
return async (...args) => {
if (runningPromise) {
nextArgs = args;
if (queuedPromise) {
return queuedPromise;
}
else {
queuedPromise = runningPromise.then(() => {
queuedPromise = undefined;
runningPromise = fn(...nextArgs);
return runningPromise;
});
return queuedPromise;
}
}
else {
runningPromise = fn(...args);
return runningPromise;
}
};
}
exports.default = asyncThrottle;
//# sourceMappingURL=asyncThrottle.js.map