An open API service indexing awesome lists of open source software.

https://github.com/wwwflorencio/await-retry


https://github.com/wwwflorencio/await-retry

async await brazil javascript new-feature nodejs promise retry-library retry-strategies

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

          

# await-retry

# install
`npm i await-retry --save`

# usage example
```js
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()
```