instantsearch.js
Version:
InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.
54 lines (41 loc) • 996 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var nextMicroTask = Promise.resolve();
var defer = function defer(callback) {
var progress = null;
var cancelled = false;
var fn = function fn() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (progress !== null) {
return;
}
progress = nextMicroTask.then(function () {
progress = null;
if (cancelled) {
cancelled = false;
return;
}
callback.apply(void 0, args);
});
};
fn.wait = function () {
if (progress === null) {
throw new Error('The deferred function should be called before calling `wait()`');
}
return progress;
};
fn.cancel = function () {
if (progress === null) {
return;
}
cancelled = true;
};
return fn;
};
var _default = defer;
exports.default = _default;
;