diff --git a/examples/multi-module/main.ts b/examples/multi-module/main.ts index 59ac6d1..b3aa93f 100644 --- a/examples/multi-module/main.ts +++ b/examples/multi-module/main.ts @@ -12,15 +12,10 @@ import { uppercase, repeat } from './text.ts'; using run = workers(1); // All four moroutines from two modules run on the same single worker - const results = await Promise.all([ - run(square(7)), - run(add(3, 4)), - run(uppercase('hello')), - run(repeat('ab', 3)), - ]); + const results = await Promise.all([run(square(7)), run(add(3, 4)), run(uppercase('hello')), run(repeat('ab', 3))]); - console.log('square(7) =', results[0]); // 49 - console.log('add(3, 4) =', results[1]); // 7 + console.log('square(7) =', results[0]); // 49 + console.log('add(3, 4) =', results[1]); // 7 console.log("uppercase('hello') =", results[2]); // HELLO - console.log("repeat('ab', 3) =", results[3]); // ababab + console.log("repeat('ab', 3) =", results[3]); // ababab } diff --git a/examples/shared-state/main.ts b/examples/shared-state/main.ts index 89d3b63..289e29d 100644 --- a/examples/shared-state/main.ts +++ b/examples/shared-state/main.ts @@ -7,7 +7,7 @@ import { workers, shared, int32, mutex } from '../../src/index.ts'; import { updatePosition } from './update-position.ts'; -const lock = mutex(); +const mu = mutex(); const pos = shared({ x: int32, y: int32 }); const steps = 1000; @@ -17,10 +17,10 @@ const steps = 1000; // 4 workers each move the position (1, 2) per step, 1000 steps each await Promise.all([ - run(updatePosition(lock, pos, 1, 2, steps)), - run(updatePosition(lock, pos, 1, 2, steps)), - run(updatePosition(lock, pos, 1, 2, steps)), - run(updatePosition(lock, pos, 1, 2, steps)), + run(updatePosition(mu, pos, 1, 2, steps)), + run(updatePosition(mu, pos, 1, 2, steps)), + run(updatePosition(mu, pos, 1, 2, steps)), + run(updatePosition(mu, pos, 1, 2, steps)), ]); } diff --git a/examples/shared-state/update-position.ts b/examples/shared-state/update-position.ts index 665ec92..c6a3ab9 100644 --- a/examples/shared-state/update-position.ts +++ b/examples/shared-state/update-position.ts @@ -5,9 +5,9 @@ type Position = SharedStruct<{ x: Int32; y: Int32 }>; export const updatePosition = mo( import.meta, - async (lock: Mutex, pos: Position, dx: number, dy: number, steps: number): Promise => { + async (mu: Mutex, pos: Position, dx: number, dy: number, steps: number): Promise => { for (let i = 0; i < steps; i++) { - using guard = await lock.lock(); + using guard = await mu.lock(); const current = pos.load(); pos.store({ x: current.x + dx, y: current.y + dy }); } diff --git a/test/shared/shared.test.ts b/test/shared/shared.test.ts index 628573e..c08e4c3 100644 --- a/test/shared/shared.test.ts +++ b/test/shared/shared.test.ts @@ -52,15 +52,15 @@ describe('shared()', () => { assert.deepEqual(rect.load(), { pos: { x: 99, y: 0 }, w: 200 }); }); - it('struct with lock excludes lock from load/store', () => { - const state = shared({ x: int32, lock: mutex }); + it('struct with mutex excludes mutex from load/store', () => { + const state = shared({ x: int32, mu: mutex }); state.store({ x: 42 }); assert.deepEqual(state.load(), { x: 42 }); }); - it('struct lock accessible via fields', async () => { - const state = shared({ x: int32, lock: mutex }); - const guard = await state.fields.lock.lock(); + it('struct mutex accessible via fields', async () => { + const state = shared({ x: int32, mu: mutex }); + const guard = await state.fields.mu.lock(); guard[Symbol.dispose](); });