Files
agency/.pnpm-store/v3/files/94/b1beb23f7ce60dd393f766eba5c42923fd1731e92ffcfdc565951cc9c2aa26dd70fb9b606b502b1c735394203a81e031e9e042a73c6448828718413a810f98
hanzo-agent 5af6960b87 run project
Run: sess_f37640604ae254cb4d11dc6217f7b721
2026-09-30 00:04:56 +00:00

70 lines
2.5 KiB
Plaintext

// src/timeoutManager.ts
var defaultTimeoutProvider = {
// We need the wrapper function syntax below instead of direct references to
// global setTimeout etc.
//
// BAD: `setTimeout: setTimeout`
// GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
//
// If we use direct references here, then anything that wants to spy on or
// replace the global setTimeout (like tests) won't work since we'll already
// have a hard reference to the original implementation at the time when this
// file was imported.
setTimeout: (callback, delay) => setTimeout(callback, delay),
clearTimeout: (timeoutId) => clearTimeout(timeoutId),
setInterval: (callback, delay) => setInterval(callback, delay),
clearInterval: (intervalId) => clearInterval(intervalId)
};
var TimeoutManager = class {
// We cannot have TimeoutManager<T> as we must instantiate it with a concrete
// type at app boot; and if we leave that type, then any new timer provider
// would need to support ReturnType<typeof setTimeout>, which is infeasible.
//
// We settle for type safety for the TimeoutProvider type, and accept that
// this class is unsafe internally to allow for extension.
#provider = defaultTimeoutProvider;
#providerCalled = false;
setTimeoutProvider(provider) {
if (process.env.NODE_ENV !== "production") {
if (this.#providerCalled && provider !== this.#provider) {
console.error(
`[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,
{ previous: this.#provider, provider }
);
}
}
this.#provider = provider;
if (process.env.NODE_ENV !== "production") {
this.#providerCalled = false;
}
}
setTimeout(callback, delay) {
if (process.env.NODE_ENV !== "production") {
this.#providerCalled = true;
}
return this.#provider.setTimeout(callback, delay);
}
clearTimeout(timeoutId) {
this.#provider.clearTimeout(timeoutId);
}
setInterval(callback, delay) {
if (process.env.NODE_ENV !== "production") {
this.#providerCalled = true;
}
return this.#provider.setInterval(callback, delay);
}
clearInterval(intervalId) {
this.#provider.clearInterval(intervalId);
}
};
var timeoutManager = new TimeoutManager();
function systemSetTimeoutZero(callback) {
setTimeout(callback, 0);
}
export {
TimeoutManager,
defaultTimeoutProvider,
systemSetTimeoutZero,
timeoutManager
};
//# sourceMappingURL=timeoutManager.js.map