30 lines
No EOL
729 B
JavaScript
Executable file
30 lines
No EOL
729 B
JavaScript
Executable file
let nextHandle = 1;
|
|
let resolved;
|
|
const activeHandles = {};
|
|
function findAndClearHandle(handle) {
|
|
if (handle in activeHandles) {
|
|
delete activeHandles[handle];
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
export const Immediate = {
|
|
setImmediate(cb) {
|
|
const handle = nextHandle++;
|
|
activeHandles[handle] = true;
|
|
if (!resolved) {
|
|
resolved = Promise.resolve();
|
|
}
|
|
resolved.then(() => findAndClearHandle(handle) && cb());
|
|
return handle;
|
|
},
|
|
clearImmediate(handle) {
|
|
findAndClearHandle(handle);
|
|
},
|
|
};
|
|
export const TestTools = {
|
|
pending() {
|
|
return Object.keys(activeHandles).length;
|
|
}
|
|
};
|
|
//# sourceMappingURL=Immediate.js.map
|