From a3c7dd896eea01ce0cc15b771f904502b8e9f4c5 Mon Sep 17 00:00:00 2001
From: Ben
Date: Wed, 11 Oct 2023 22:37:07 +0200
Subject: [PATCH] Fix timeout clear
---
packages/massa-web3/package.json | 2 +-
packages/massa-web3/src/utils/time.ts | 2 +-
packages/massa-web3/src/web3/EventPoller.ts | 12 ++++++------
packages/massa-web3/test/web3/evenPoller.spec.ts | 1 +
4 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/packages/massa-web3/package.json b/packages/massa-web3/package.json
index 79f9da43..6f1ca7e7 100644
--- a/packages/massa-web3/package.json
+++ b/packages/massa-web3/package.json
@@ -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",
diff --git a/packages/massa-web3/src/utils/time.ts b/packages/massa-web3/src/utils/time.ts
index 4d6a869e..c08e561c 100644
--- a/packages/massa-web3/src/utils/time.ts
+++ b/packages/massa-web3/src/utils/time.ts
@@ -23,7 +23,7 @@ export class Timeout {
}
private isCleared: boolean;
private isCalled: boolean;
- private timeoutHook: NodeJS.Timeout;
+ private timeoutHook: ReturnType;
/**
* Clears the timeout so that the callback function is not called.
diff --git a/packages/massa-web3/src/web3/EventPoller.ts b/packages/massa-web3/src/web3/EventPoller.ts
index 2b5d8869..bf8dd66f 100644
--- a/packages/massa-web3/src/web3/EventPoller.ts
+++ b/packages/massa-web3/src/web3/EventPoller.ts
@@ -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();
+ });
}
/**
@@ -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();
+ });
}
/**
diff --git a/packages/massa-web3/test/web3/evenPoller.spec.ts b/packages/massa-web3/test/web3/evenPoller.spec.ts
index 52887f85..2ccda9aa 100644
--- a/packages/massa-web3/test/web3/evenPoller.spec.ts
+++ b/packages/massa-web3/test/web3/evenPoller.spec.ts
@@ -147,6 +147,7 @@ describe('EventPoller', () => {
).toHaveBeenCalledTimes(1);
jest.useRealTimers();
+ eventPoller.stopPolling();
});
});