@reactivex/rxjs
Version:
Reactive Extensions for modern JavaScript
40 lines • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var nextHandle = 1;
var RESOLVED = (function () { return Promise.resolve(); })();
var activeHandles = {};
/**
* Finds the handle in the list of active handles, and removes it.
* Returns `true` if found, `false` otherwise. Used both to clear
* Immediate scheduled tasks, and to identify if a task should be scheduled.
*/
function findAndClearHandle(handle) {
if (handle in activeHandles) {
delete activeHandles[handle];
return true;
}
return false;
}
/**
* Helper functions to schedule and unschedule microtasks.
*/
exports.Immediate = {
setImmediate: function (cb) {
var handle = nextHandle++;
activeHandles[handle] = true;
RESOLVED.then(function () { return findAndClearHandle(handle) && cb(); });
return handle;
},
clearImmediate: function (handle) {
findAndClearHandle(handle);
},
};
/**
* Used for internal testing purposes only. Do not export from library.
*/
exports.TestTools = {
pending: function () {
return Object.keys(activeHandles).length;
}
};
//# sourceMappingURL=Immediate.js.map