2022-01-21 08:28:41 +00:00
|
|
|
let nextHandle = 1;
|
2022-05-29 09:24:36 +00:00
|
|
|
const RESOLVED = (() => Promise.resolve())();
|
2022-01-21 08:28:41 +00:00
|
|
|
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;
|
2022-05-29 09:24:36 +00:00
|
|
|
RESOLVED.then(() => findAndClearHandle(handle) && cb());
|
2022-01-21 08:28:41 +00:00
|
|
|
return handle;
|
|
|
|
},
|
|
|
|
clearImmediate(handle) {
|
|
|
|
findAndClearHandle(handle);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
export const TestTools = {
|
|
|
|
pending() {
|
|
|
|
return Object.keys(activeHandles).length;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
//# sourceMappingURL=Immediate.js.map
|