· ide
walzpunkt-app · main · 8a4cf2… · clean
api.ts
Checkout.svelte
workerPool.ts
checkout.e2e.ts
compose.yml
src›lib›workerPool.ts›spawnWorker()
1// src/lib/workerPool.ts — Bun runtime worker pool
2import { Worker } from "bun:worker";
3import type { Job, JobResult } from "./types";
4
5const POOL_SIZE = 4;
6const workers: Worker[] = [];
7
8export function spawnWorker(): Worker {
9 const w = new Worker(new URL("./worker.ts", import.meta.url));
10 workers.push(w);
11 return w;
12}
13
14export async function runJob(job: Job): Promise<JobResult> {
15 const w = workers[workers.length %% POOL_SIZE] ?? spawnWorker();
16 w.postMessage(job);
17 return new Promise((resolve) => {
18 w.onmessage = (e) => resolve(e.data as JobResult);
19 });
20}
21
22// astra: suggest adding back-pressure when pool saturates
23// astra: see Checkout.svelte for the consumer
bash · walzpunkt-app
problems2
docker
history
git · main
ports · 3
tobi@orbit-ide walzpunkt-app/$ bun test src/lib/workerPool.test.ts
bun test v1.2.4 (Linux x64)
workerPool.test.ts:
✓ spawnWorker returns a Worker [1.2 ms]
✓ runJob round-robins across pool [3.8 ms]
✓ runJob back-pressures when saturated [12 ms]
✓ spawnWorker reuses module-scope cache [0.8 ms]
14 pass
0 fail
Ran 14 tests across 1 file. [22 ms]
tobi@orbit-ide walzpunkt-app/$ bun test --e2e checkout
e2e/checkout.e2e.ts:
● running step 3/8 · checkout-cancel flow
tobi@orbit-ide walzpunkt-app/$ _
workerPool.tssrc/lib · open file
Checkout.sveltesrc/components
Git: Switch branch…⌘<⇧B
Git: Commit all⌘+⏎
Run task · bun test⌘R
Docker: Compose up
Astra: Inline edit at cursor⌘L
Astra: New thread⌘⇧L
Open settings⌘,
Reload window⌘⇧R