Download react-query/packages/query-core/src/removable.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 851 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/query-core/src/removable.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/query-core/src/removable.ts
-
curl -L -o removable.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/query-core/src/removable.ts
851 Bytes
| import { isServer, isValidTimeout } from './utils' | |
| export abstract class Removable { | |
| gcTime!: number | |
| #gcTimeout?: ReturnType<typeof setTimeout> | |
| destroy(): void { | |
| this.clearGcTimeout() | |
| } | |
| protected scheduleGc(): void { | |
| this.clearGcTimeout() | |
| if (isValidTimeout(this.gcTime)) { | |
| this.#gcTimeout = setTimeout(() => { | |
| this.optionalRemove() | |
| }, this.gcTime) | |
| } | |
| } | |
| protected updateGcTime(newGcTime: number | undefined): void { | |
| // Default to 5 minutes (Infinity for server-side) if no gcTime is set | |
| this.gcTime = Math.max( | |
| this.gcTime || 0, | |
| newGcTime ?? (isServer ? Infinity : 5 * 60 * 1000), | |
| ) | |
| } | |
| protected clearGcTimeout() { | |
| if (this.#gcTimeout) { | |
| clearTimeout(this.#gcTimeout) | |
| this.#gcTimeout = undefined | |
| } | |
| } | |
| protected abstract optionalRemove(): void | |
| } | |