Skip to content

Instantly share code, notes, and snippets.

@martinheidegger
Created November 7, 2015 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinheidegger/a7cf754d91f847c29965 to your computer and use it in GitHub Desktop.
Save martinheidegger/a7cf754d91f847c29965 to your computer and use it in GitHub Desktop.
Attempts for connecting to tcp server
var that = this
var makeAttempt = function () {
if (ports.length > 0) {
net.createConnection({port: ports[0]}, function () {
// test all ports
ports.shift()
makeAttempt()
}).on("error", function (e) {
attempt ++
if (attempt < 100) {
setTimeout(makeAttempt, 200)
} else {
exercise.emit('fail', 'Timeout occured')
}
})
} else {
query.call(that, mode)
return
}
}
makeAttempt()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment