Skip to content

Instantly share code, notes, and snippets.

@FirstWhack
Last active August 29, 2015 14:11
Show Gist options
  • Save FirstWhack/4ea07f0a11351c74fce8 to your computer and use it in GitHub Desktop.
Save FirstWhack/4ea07f0a11351c74fce8 to your computer and use it in GitHub Desktop.
function runCheck(host, cb) {
console.log('Checking for life at ' + host + ' we checked '+ checks + ' times so far');
var checkReq = http.get(host, function(res) {
console.log("Got response: " + res.statusCode);
ret = 'online';
checkReq.clearTimeout();
console.log('Timeout cleared and sending them on their way');
cb(true); // we are solid
}).on('error', function(e) {
console.log('error' + e);
turnOn();
cb(false);
});
// I hate waiting.. Let's set a timeout
checkReq.setTimeout( 4000, function( ) { // 4 seconds is usually enough
console.log('I timed out bro, lets try to turn it on?');
checkReq.abort();
console.log('Aborted : moving to `turnOn()`');
turnOn();
cb(false);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment