File
Blob: src/node/internal/internal_timers_global_override.ts
| 1 | // Copyright (c) 2017-2025 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | |
| 5 | // This module overrides globalThis timer functions with Node.js-compatible versions |
| 6 | // when loaded. It is loaded by worker.c++ when enable_nodejs_global_timers compat |
| 7 | // flag is enabled. |
| 8 | // |
| 9 | // After loading: |
| 10 | // - globalThis.setTimeout and globalThis.setInterval return Timeout objects |
| 11 | // with methods like refresh(), ref(), unref(), and hasRef() instead of numeric IDs |
| 12 | // - globalThis.setImmediate and globalThis.clearImmediate are available |
| 13 | |
| 14 | import { |
| 15 | setTimeout, |
| 16 | setInterval, |
| 17 | clearTimeout, |
| 18 | clearInterval, |
| 19 | } from 'node-internal:internal_timers'; |
| 20 | |
| 21 | globalThis.setTimeout = setTimeout as unknown as typeof globalThis.setTimeout; |
| 22 | globalThis.setInterval = |
| 23 | setInterval as unknown as typeof globalThis.setInterval; |
| 24 | globalThis.clearTimeout = |
| 25 | clearTimeout as unknown as typeof globalThis.clearTimeout; |
| 26 | globalThis.clearInterval = |
| 27 | clearInterval as unknown as typeof globalThis.clearInterval; |