Created
October 8, 2012 15:25
-
-
Save rtyley/3853105 to your computer and use it in GitHub Desktop.
sketchy attempt to do retries with dispatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
the thread sleep is still a problem tho
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
if you flatMap on line 2 maybe you don't have to apply on line 8?