*** EDIT *** I have tried this..
StartPollingServer: () => {
return setInterval(() => {
MyTest.PollingServer();
}, 1000);
}
and also have tried
StartPollingServer: () => {
const a =
setInterval(() => {
MyTest.PollingServer();
}, 1000);
return a;
},
and still the variable test comes back empty
I am unsure why the clearInterval isn't clearing the setInterval after running for 10 seconds, can someone point out why the clearInterval isn't working
var MyTest = MyTest || {};
MyTest = {
StartPollingServer: () => {
setInterval(() => {
MyTest.PollingServer();
}, 1000);
},
PollingServer: () => {
console.log("Polling Server");
},
StopPollingServer: (f) => {
clearInterval(f);
f = null;
}
}
var test = MyTest.StartPollingServer();
setTimeout(() => {
MyTest.StopPollingServer(test);
}, 10000);
Your
fis not the correct interval handle.You need to store the result of
setIntervalinto some property and then use that into theclearInterval.In my example I used a variable outside the object but you may use
thisandfunctionto be able to reference thefproperty within your object