Skip to content

Instantly share code, notes, and snippets.

@yjbanov
Last active August 29, 2015 14:05
Show Gist options
  • Save yjbanov/9b22dab22e03c7c3cbac to your computer and use it in GitHub Desktop.
Save yjbanov/9b22dab22e03c7c3cbac to your computer and use it in GitHub Desktop.
Quiver delay function composition 1
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