Skip to content

Commit

Permalink
fix: isFinished never set on waiter (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x authored Mar 5, 2025
1 parent 379dc9b commit 9c1d2b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/helpers/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as events from 'node:events';
import { timeout } from '../time';
import { timeout, waiter } from '../time';

describe('Helper tests', () => {
test('timeout function should not cause memory leak by accumulating abort listeners on abort', async () => {
Expand Down Expand Up @@ -49,4 +49,11 @@ describe('Helper tests', () => {
// Final check to confirm listeners are cleaned up
expect(countListeners()).toBe(0);
});

test('waiter is finished', async () => {
const myWaiter = waiter();
myWaiter.finish();
await myWaiter;
expect(myWaiter.isFinished).toBe(true);
});
});
2 changes: 1 addition & 1 deletion src/helpers/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function waiter<T = void>(): Waiter<T> {
});
const completer = {
finish: (result: T) => {
completer.isFinished = true;
void Object.assign(promise, { isFinished: true });
resolveFn(result);
},
isFinished: false,
Expand Down

0 comments on commit 9c1d2b3

Please sign in to comment.