Return type of fn
Async function to call. Must return a value.
Maximum age of cached result
slow by default
Value
const f = updateOutdated(async () => {
const r = await fetch(`blah`);
return await r.json();
}, 60*1000);
// Result will be JSON from fetch. If fetch happened already in the
// last 60s, return cached result. Otherwise it will fetch data
const result = await f();
Callback fn is passed how many milliseconds have elapsed since last update. Its minimum value will be interval.
const f = updateOutdated(async elapsedMs => {
// Do something with elapsedMs?
}, 60*1000;
There are different policies for what to happen if fn fails. slow is the default.
fast: Invocation will happen immediately on next attemptslow: Next invocation will wait interval as if it was successfulbackoff: Attempts will get slower and slower until next success. Interval is multipled by 1.2 each time.
Calls the async
fnto generate a value if there is no prior value orintervalhas elapsed since value was last generated.