Skip to content

Instantly share code, notes, and snippets.

@rtyley
Created October 8, 2012 15:25
Show Gist options
  • Save rtyley/3853105 to your computer and use it in GitHub Desktop.
Save rtyley/3853105 to your computer and use it in GitHub Desktop.
sketchy attempt to do retries with dispatch
def getWithRetries(retries: Int) : Promise[Either[Throwable, String]] = {
Http(url OK as.Response(r => r.getResponseBody)).either.map {
_ match {
case fail: Left[Throwable, String] =>
println("Download attempt failed - remaining retries: "+retries+" : " + fail.a.getMessage)
if (retries > 0) {
Thread.sleep(5000 / retries)
getWithRetries(retries - 1)() // probably bad?
} else fail
case s => s
}
}
}
@n8han
Copy link

n8han commented Oct 8, 2012

if you flatMap on line 2 maybe you don't have to apply on line 8?

@n8han
Copy link

n8han commented Oct 8, 2012

the thread sleep is still a problem tho

@n8han
Copy link

n8han commented Oct 8, 2012

ohhhh... we need a Promise.sleep(delay: Int), then you can flatMap that... this is going to be cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment