Skip to content

Commit c4760a6

Browse files
Properly clean up timers
1 parent 5eae169 commit c4760a6

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

app/core/BackgroundBridge/createDupeReqFilterStream.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const THREE_MINUTES = inMilliseconds(3, Duration.Minute);
1111
const makeExpirySet = () => {
1212
const map: Map<string | number | null, number> = new Map();
1313

14-
setInterval(() => {
14+
const timerId = setInterval(() => {
1515
const cutoffTime = Date.now() - THREE_MINUTES;
1616

1717
for (const [id, timestamp] of map.entries()) {
@@ -37,6 +37,14 @@ const makeExpirySet = () => {
3737
}
3838
return false;
3939
},
40+
41+
/**
42+
* Destroy the set and tear down the underlying timer.
43+
*/
44+
destroy() {
45+
map.clear();
46+
clearInterval(timerId);
47+
},
4048
};
4149
};
4250

@@ -62,6 +70,10 @@ export default function createDupeReqFilterStream() {
6270
cb();
6371
}
6472
},
73+
destroy(error, cb) {
74+
seenRequestIds.destroy();
75+
cb(error);
76+
},
6577
objectMode: true,
6678
});
6779
}

0 commit comments

Comments
 (0)