You're misunderstanding the setTimeout
function.
The setTimeout
function takes a function and executes it later.
By writing setTimeout(doRequest(url,proxys[proxy]), proxytimeout)
, you're _calling the doRequest
function (immediately), and passing the result (assuming that it returns another function) to setTimeout
.
You need to pass doRequest
's parameters to setTimeout
, like this:
setTimeout(doRequest, proxytimeout, url, proxys[proxy]);
This will pass setTimeout
the doRequest
function itself (without calling it first), and will also pass it the parameters to give to doRequest
when it finally calls it.