Skip to content

Commit

Permalink
Fix timeout clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Oct 11, 2023
1 parent 6f5a465 commit a3c7dd8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/massa-web3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"update-version-major": "npm version major",
"update-version-minor": "npm version minor",
"update-version-patch": "npm version patch",
"test": "jest",
"test": "jest ----detectOpenHandles --forceExit",
"test:watch": "jest --watch",
"test:watch:all": "jest --watchAll",
"test:cov": "jest --coverage",
Expand Down
2 changes: 1 addition & 1 deletion packages/massa-web3/src/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Timeout {
}
private isCleared: boolean;
private isCalled: boolean;
private timeoutHook: NodeJS.Timeout;
private timeoutHook: ReturnType<typeof setTimeout>;

/**
* Clears the timeout so that the callback function is not called.
Expand Down
12 changes: 6 additions & 6 deletions packages/massa-web3/src/web3/EventPoller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ export class EventPoller extends EventEmitter {
}

// reset the interval.
this.timeoutId = new Timeout(this.pollIntervalMillis, () =>
this.callback(),
);
this.timeoutId = new Timeout(this.pollIntervalMillis, () => {
this.callback();
});
}

/**
Expand All @@ -133,9 +133,9 @@ export class EventPoller extends EventEmitter {
if (this.timeoutId) {
return;
}
this.timeoutId = new Timeout(this.pollIntervalMillis, () =>
that.callback(),
);
this.timeoutId = new Timeout(this.pollIntervalMillis, () => {
that.callback();
});
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/massa-web3/test/web3/evenPoller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ describe('EventPoller', () => {
).toHaveBeenCalledTimes(1);

jest.useRealTimers();
eventPoller.stopPolling();
});
});

Expand Down

0 comments on commit a3c7dd8

Please sign in to comment.