Skip to content

Commit 768f73a

Browse files
committed
Chore: Allow disposing worker projection proxy more than once
1 parent 60bb9cd commit 768f73a

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/workers/WorkerProxyProjection.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class WorkerProxyProjection<
3232
readonly #remoteView: Comlink.Remote<TView>;
3333
readonly #logger?: ILogger;
3434
readonly #messageTypes: string[];
35+
#disposed = false;
3536
viewLocker?: IViewLocker = new InMemoryLock();
3637

3738
get remoteProjection(): Comlink.Remote<TProjection> {
@@ -160,6 +161,10 @@ export class WorkerProxyProjection<
160161
}
161162

162163
dispose() {
164+
if (this.#disposed)
165+
return;
166+
167+
this.#disposed = true;
163168
this.#remoteProjection[Comlink.releaseProxy]();
164169
this.#remoteView[Comlink.releaseProxy]();
165170
this.#worker?.terminate();

tests/integration/workers/AbstractWorkerProjection.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ describe('AbstractWorkerProjection', () => {
127127
expect(await projectionProxy.view.getCounter()).toBe(1);
128128
});
129129

130+
it('allows disposing the projection proxy more than once', async () => {
131+
132+
await projectionProxy.ensureWorkerReady();
133+
134+
expect(() => projectionProxy.dispose()).not.toThrow();
135+
expect(() => projectionProxy.dispose()).not.toThrow();
136+
});
137+
130138
it('awaits project calls while restoring', async () => {
131139

132140
const eventStore = createEventStore([

0 commit comments

Comments
 (0)