async-iterator-retry

1.0.0 • Public • Published

async-iterator-retry npm version

Retry async iteraotrs.

Overview

Like promise-retry but for async iterators, also based on retry.

Usage

const asyncIteratorRetry = require('async-iterator-retry')
 
const options = {
  retries: 10, // The maximum amount of times to retry the operation. Default is 10.
  factor: 2, // The exponential factor to use. Default is 2.
  minTimeout: 1000, // The number of milliseconds before starting the first retry. Default is 1000.
  maxTimeout: Infinity, // The maximum number of milliseconds between two retries. Default is Infinity.
  randomize: false // Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.
}
 
const iteratorWithRetry = asyncIteratorRetry(async function * (retry, attempt) {
  if (attempt > 1) {
    console.log(`Retrying, attempt ${attempt}...`)
  }
 
  const iterator = getSomeIterator()
 
  try {
    yield * iterator
  } catch (err) {
    if (err.code === 'ETIMEDOUT') {
      yield * retry(err)
    }
 
    throw err
  }
 
}, options)
 
for await const (item of myIteratorWithRetry) {
  console.log(item)
}

Readme

Keywords

none

Package Sidebar

Install

npm i async-iterator-retry

Weekly Downloads

0

Version

1.0.0

License

Unlicense

Unpacked Size

2.34 kB

Total Files

3

Last publish

Collaborators

  • valeriangalliat