(
provider: TimeoutProvider<TTimerId>,
)
| 70 | #providerCalled = false |
| 71 | |
| 72 | setTimeoutProvider<TTimerId extends ManagedTimerId>( |
| 73 | provider: TimeoutProvider<TTimerId>, |
| 74 | ): void { |
| 75 | if (process.env.NODE_ENV !== 'production') { |
| 76 | if (this.#providerCalled && provider !== this.#provider) { |
| 77 | // After changing providers, `clearTimeout` will not work as expected for |
| 78 | // timeouts from the previous provider. |
| 79 | // |
| 80 | // Since they may allocate the same timeout ID, clearTimeout may cancel an |
| 81 | // arbitrary different timeout, or unexpected no-op. |
| 82 | // |
| 83 | // We could protect against this by mixing the timeout ID bits |
| 84 | // deterministically with some per-provider bits. |
| 85 | // |
| 86 | // We could internally queue `setTimeout` calls to `TimeoutManager` until |
| 87 | // some API call to set the initial provider. |
| 88 | console.error( |
| 89 | `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`, |
| 90 | { previous: this.#provider, provider }, |
| 91 | ) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | this.#provider = provider |
| 96 | if (process.env.NODE_ENV !== 'production') { |
| 97 | this.#providerCalled = false |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId { |
| 102 | if (process.env.NODE_ENV !== 'production') { |
no outgoing calls
no test coverage detected