I have a function that I would like to stop when the function is called. How would I do this? Here is my code:
function waitforsend(tdate, messagecontent) { //https://stackoverflow.com/questions/22125865/wait-until-flag-true
cdate = Math.floor(new Date().getTime())/1000 - 18000
if(cdate <= tdate) {
setTimeout(function(){
waitforsend(tdate, messagecontent)
}, 1000);
} else {
client.channels.cache.get(eventchannelid.toString()).send(messagecontent)
fs.renameSync('./events/' + tdate + '.json', './pastevents/' + tdate + '.json', function(err){
if(err){
console.log(colors.red('Issue removing file ' + tdate +', removing file'))
fs.unlink(tdate + '.json', function(err){
if(err){console.log(colors.red('Issue with removing file, please mannualy remove.'))}
})
}
})
console.log('I got here')
Scan()
}
}
How can i stop the execution of waitforsend() when Another instance of it is called. The issue is from calling Scan(), which will read a file and then call waitforsend(). Scan() is also called when a file is created, and this leads to waitforsend() trying to move a file that doesnt exist. How can I solve this?