Skip to content

Instantly share code, notes, and snippets.

@sivagao
Forked from kriskowal/gist:593052
Last active December 27, 2015 18:39
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 sivagao/7371435 to your computer and use it in GitHub Desktop.
Save sivagao/7371435 to your computer and use it in GitHub Desktop.
httpretry.coffee
Q = require 'q'
HTTP = require 'q-http'
httpReadRetry = (url, timeout, times) ->
HTTP.read(url).then(
(content) ->
{content}
,(error) ->
if times is 0
throw new Error 'Cant read #{JSON.stringify(url)}'
Q.delay(timeout).then ->
httpReadRetry url, timeout, times-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment