Re-run the IO if it raises an error, up to the given number of times. By
default, the action is retried immediately. A RetryOptions
object
may be provided for more advanced use cases, such as exponential backoff.
A filter function can be used to only retry certain types of error.
const action = IO(() => fs.promises.readFile("./readme.md"));
// Retry once if the first attempt fails.
action.retry(1);
// Retry 3 times, after 1 second, then 2 seconds, then 4 seconds.
action.retry({
count: 3,
delay: [1, 'second'],
backoff: 2,
});
// Retry only if the file does not exist.
action.retry({
count: 1,
filter: (error: any) => error.code === 'ENOENT'
});
Run this action, performing any side-effects, and return the result.
If the action raises an error, it is thrown. It the action cancels,
a CancellationError
is thrown.
You should ideally only call this once at the top level of your
program, or when frameworks need to interoperate with code using
IO
.
Run this action, performing any side-effects, and return an object
representing the outcome. If the action raises an error or cancels,
the returned promise will still resolve. If you want to throw errors,
use run
instead.
You should ideally only call this once at the top level of your
program, or when frameworks need to interoperate with code using
IO
.
Generated using TypeDoc
This method type-casts any errors raised by this IO to the given type. This can easily cause type unsoundness problems, so use with care.