Skip to content

Instantly share code, notes, and snippets.

@domenic
domenic / promise-retryer.js
Last active September 16, 2023 02:43
Generalized promise retryer
"use strict";
// `f` is assumed to sporadically fail with `TemporaryNetworkError` instances.
// If one of those happens, we want to retry until it doesn't.
// If `f` fails with something else, then we should re-throw: we don't know how to handle that, and it's a
// sign something went wrong. Since `f` is a good promise-returning function, it only ever fulfills or rejects;
// it has no synchronous behavior (e.g. throwing).
function dontGiveUp(f) {
return f().then(
undefined, // pass through success