Last active
August 29, 2015 14:05
-
-
Save yjbanov/9b22dab22e03c7c3cbac to your computer and use it in GitHub Desktop.
Quiver delay function composition 1
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
typedef Object OnErrorFunc(Object err, int retry, Duration elapsed); | |
typedef Duration RetryDelayFunc(Object err, int retry, Duration elapsed); | |
Future start( | |
AttemptFunc attempt, { | |
OnErrorFunc onError: retriesInfinite, | |
RetryDelayFunc retryDelay: delayNone, | |
Stopwatch runTime}) | |
---------------------------------------------------------------------------- | |
import 'package:quiver/retry.dart' as retry; | |
var limited = retry.makeRetriesLimited(10, new Duration(seconds: 10)); | |
onError(err, iteration, elapsed) => | |
is404(err) ? err : limited(err, iteration, elapsed); | |
delayFn(err, iteration, elapsed) => | |
is503(err) | |
? retry.randomDelay(new Duration(seconds: 1), 0.8) | |
: retry.capDelay(retry.randomDelay(new Duration(seconds: 1), 0.4), | |
const Duration(milliseconds: 1200)); | |
retry.start(doSomething, onError: onError, retryDelay: delayFn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment