implemented timeoutManager, a more efficient solution for managing timeouts in RAM memory. this resolves the problem of lingering timeouts in the server, providing faster removal of old timeouts and improving overall performance.
20 lines
548 B
JavaScript
20 lines
548 B
JavaScript
const timeoutManager = {
|
|
timeouts: new Map(),
|
|
add: function (roomId, timeoutId) {
|
|
this.timeouts.set(roomId, timeoutId);
|
|
},
|
|
get: function (roomId) {
|
|
return this.timeouts.get(roomId);
|
|
},
|
|
clear: function (roomId) {
|
|
clearTimeout(this.timeouts.get(roomId));
|
|
this.timeouts.delete(roomId);
|
|
},
|
|
set: function (timeoutFunction, time, roomId) {
|
|
const timeoutId = setTimeout(timeoutFunction, time, roomId);
|
|
this.add(roomId, timeoutId);
|
|
},
|
|
};
|
|
|
|
module.exports = timeoutManager;
|