Spaces:
Paused
Paused
Download packages/frontend/src/components/menu/formatter/format-queue.ts from f4b404/aiostreams: direct link, hf CLI and curl.
- Browser
- Download file 744 Bytes
-
https://huggingface.co/spaces/f4b404/aiostreams/resolve/main/packages/frontend/src/components/menu/formatter/format-queue.ts
- Command line
-
hf download hf://spaces/f4b404/aiostreams/packages/frontend/src/components/menu/formatter/format-queue.ts
-
curl -L -o format-queue.ts https://huggingface.co/spaces/f4b404/aiostreams/resolve/main/packages/frontend/src/components/menu/formatter/format-queue.ts
744 Bytes
| export class FormatQueue { | |
| private queue: (() => Promise<void>)[] = []; | |
| private processing = false; | |
| private readonly delay: number; | |
| constructor(delay: number) { | |
| this.delay = delay; | |
| } | |
| enqueue(formatFn: () => Promise<void>) { | |
| this.queue = [formatFn]; | |
| this.process(); | |
| } | |
| private async process() { | |
| if (this.processing) return; | |
| this.processing = true; | |
| while (this.queue.length > 0) { | |
| const formatFn = this.queue.shift(); | |
| if (formatFn) { | |
| try { | |
| await formatFn(); | |
| } catch (error) { | |
| console.error('Error in format queue:', error); | |
| } | |
| await new Promise((resolve) => setTimeout(resolve, this.delay)); | |
| } | |
| } | |
| this.processing = false; | |
| } | |
| } | |