I have a class in one javascript file communicator.js
let communicator = null;
getCommunicator = function () {
if (!communicator) {
Log.info("Creating new communicator...");
communicator = new Communicator();
}
return communicator;
};
In order to retrieve the Communicator object I call the getCommunicator()-function in many places in the code to get the same communicator every time, i.e. a singleton.
My intention is thus that, once created, the Communicator object should persist in the global scope forever.
However I have seen that after some inactivity time on my webappliaction, the next time getCommunicator() is called it seems that the reference is gone and it has to create a new.
So any ideas why this is happening? Am I creating the global variable incorrectly? Or does a object has a life time in node?
Well, yeah its created first time when called in a Meteor method. But if I call the method several times in close time period it is not recreated. So solution would be to change it to var?