Skip to content

wwwmarcos/await-retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

await-retry

install

npm i await-retry --save

usage example

const { retry } = require('await-retry')

function getUser () {
  return {
    message: 'wow, amazing',
    user: {
      name: 'enzo'
    }
  }
}

function getUserWithError () {
  throw new Error('oh no')
}

async function start () {
  console.log(await retry(getUser, { tries: 2 }))
  /**
    {
     tries: 1,
     success: true,
     result: { message: 'wow, amazing', user: { name: 'enzo' } },
    }
   */

  console.log(await retry(getUserWithError, { tries: 2 }))
  /**
   * {
       tries: 2,
       success: false,
       errors: [Error: oh no..., Error: oh no]
     }
   */
}

start()