You can set up a boolean var to track if your polling is currently running. Something like this for example:
var polling = false;
function longPoll(){
//do nothing if already polling
if( polling )
{
return;
}
//set polling to true
polling = true;
//rest of function code goes here...
//set polling to false after process is finished
polling = false;
setTimeout(function(){
longPoll();
console.log('polling: '+new Date().getTime());
}, 5000);
};