Skip to content

Instantly share code, notes, and snippets.

@hmpmarketing
Created October 29, 2018 08:59
Show Gist options
  • Save hmpmarketing/5934d3295f2ba4e355fc44e662ab1c4e to your computer and use it in GitHub Desktop.
Save hmpmarketing/5934d3295f2ba4e355fc44e662ab1c4e to your computer and use it in GitHub Desktop.
proxyTimer = async function (delay,callback) {
return new Promise((resolve, reject) => {
var timeleft = delay;
var proxyTimer = setInterval(function(){
timeleft--;
if(timeleft <= 0){
clearInterval(proxyTimer)
callback()
}else{
resolve(true)
}
},1000);
})
}
//Calling it
proxy_time = 600 //10min
if(proxy_time){
await proxyTimer(proxy_time,async function(){
console.log('Timer Exceeded');
//Async function that makes a server call
await helpers.endSession(webdomain, instance_id,'', 'Timer Exceeded')
.then(function(){
return process.exit();
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment