-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadme.hbs
59 lines (47 loc) · 1.64 KB
/
readme.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# retryify [![NPM version][npm-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coverage Status][coverage-image]][coverage-url] [![Greenkeeper][gk-image]][gk-url]
Quickly and easily wrap functions to make them retry when they fail.
## Installation
```bash
$ npm install retryify
```
## Example
```js
// create a new retryify wrapper with some options set.
const retryify = require('retryify')({
retries: 5,
timeout: 1000,
factor: 2,
errors: [RequestError, StatusCodeError],
log: function(msg) { console.log(msg); },
});
// promisified request library
const request = require('request-promise');
// get will now retry each time it catches a RequestError or a
// StatusCodeError, it retries 5 times, or the request finally resolves
// successfully.
const get = retryify(function(url) {
return request(url);
});
// or, add some custom options for this specific function
const post = retryify({
retries: 10
}, function(url, data) {
return request({
uri: url,
method: 'POST',
});
});
// send the request, but retry if it fails.
get('http://google.com')
.then(...)
.catch(...);
```
{{>all-docs}}
[npm-url]: https://www.npmjs.com/package/retryify
[npm-image]: https://img.shields.io/npm/v/retryify.svg?style=flat-square
[ci-url]: https://travis-ci.com/smartcar/retryify
[ci-image]: https://img.shields.io/travis/com/smartcar/retryify/master.svg?style=flat-square
[coverage-url]: https://codecov.io/gh/smartcar/retryify
[coverage-image]: https://img.shields.io/codecov/c/github/smartcar/retryify/master.svg?style=flat-square
[gk-url]: https://greenkeeper.io
[gk-image]: https://badges.greenkeeper.io/smartcar/retryify.svg?style=flat-square