Offload functions to worker threads with shared memory primitives for Node.js.
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: replace Tuple.get() with public .elements array

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+7 -23
+2 -12
src/shared/tuple.ts
··· 6 6 7 7 /** A fixed-length ordered list of shared-memory values with bulk `load()`/`store()` access. */ 8 8 export class Tuple<T extends Loadable<any>[]> implements Loadable<TupleValues<T>> { 9 - private readonly elements: T; 9 + /** The individual Loadable elements, typed per index. */ 10 + readonly elements: T; 10 11 readonly length: number; 11 12 12 13 constructor(elements: T) { 13 14 this.elements = elements; 14 15 this.length = elements.length; 15 - } 16 - 17 - /** 18 - * Returns the Loadable at the given index. 19 - * @param index - Zero-based element index. Throws if out of bounds. 20 - */ 21 - get(index: number): T[number] { 22 - if (index < 0 || index >= this.length) { 23 - throw new RangeError(`Index ${index} out of bounds for tuple of length ${this.length}`); 24 - } 25 - return this.elements[index]; 26 16 } 27 17 28 18 load(): TupleValues<T> {
+5 -11
test/shared/tuple.test.ts
··· 14 14 assert.deepEqual(t.load(), [42, 99n, true]); 15 15 }); 16 16 17 - it('get() returns element Loadable', () => { 17 + it('elements provides direct access to each Loadable', () => { 18 18 const t = shared([int32, int32]); 19 - t.get(0).store(10); 20 - t.get(1).store(20); 19 + t.elements[0].store(10); 20 + t.elements[1].store(20); 21 21 assert.deepEqual(t.load(), [10, 20]); 22 22 }); 23 23 ··· 26 26 assert.equal(t.length, 3); 27 27 }); 28 28 29 - it('get() out of bounds throws', () => { 30 - const t = shared([int32]); 31 - assert.throws(() => t.get(1), /out of bounds/i); 32 - assert.throws(() => t.get(-1), /out of bounds/i); 33 - }); 34 - 35 29 it('tuple elements share one buffer', () => { 36 30 const t = shared([int32, int32]); 37 31 const SHARED = Symbol.for('moroutine.shared'); 38 - const s0 = (t.get(0) as any)[SHARED](); 39 - const s1 = (t.get(1) as any)[SHARED](); 32 + const s0 = (t.elements[0] as any)[SHARED](); 33 + const s1 = (t.elements[1] as any)[SHARED](); 40 34 assert.equal(s0.buffer, s1.buffer); 41 35 }); 42 36