Skip to content
Brian Cavalier edited this page Aug 13, 2017 · 3 revisions

Retry a stream up to N times after failures.

import { throwError, recoverWith } from 'most'

// retry :: number -> Stream a -> Stream a
// return a stream that retries the behavior of the input
// stream up to n times after errors. n must be >= 0.
// When n === 0, the returned stream will be indistinguishable
// from the input stream.
const retry = (n, stream) =>
  recoverWith(e => n <= 0 ? throwError(e) : retry(n - 1, stream),
    stream)
Clone this wiki locally