()
| 1 | /* Shared handle tables. One `makeState()` per `createWorker` so multiple workers don't share open IndexedDB connections. */ |
| 2 | |
| 3 | export const makeState = () => { |
| 4 | const dbs = []; |
| 5 | |
| 6 | const allocDb = (idb) => { dbs.push(idb); return dbs.length - 1; }; |
| 7 | const db = (h) => { |
| 8 | if (h < 0 || h >= dbs.length || dbs[h] === null) { |
| 9 | throw new Error('invalid db handle: ' + h); |
| 10 | } |
| 11 | return dbs[h]; |
| 12 | }; |
| 13 | |
| 14 | return { dbs, allocDb, db }; |
| 15 | }; |