ludo-web-multiplayer/backend/models/timeoutManager.js
Wenszel e5a69fa4a9 fixed timeout issue
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.
2023-12-20 10:31:09 +01:00

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;