How to use the retry function from async

Find comprehensive JavaScript async.retry code examples handpicked from public code repositorys.

161
162
163
164
165
166
167
168
169
170
    // 只在没有指定搜索条件时显示
    console.log('获取第%d页中的影片链接 ( %s )...'.green, pageIndex, url);
}

let retryCount = 1;
async.retry(3,
    function (callback) {
        let options = program.nomag ? { url: url, headers: { 'Cookie': 'existmag=all' } } : { url: url };
        request
            .get(options, function (err, res, body) {
fork icon214
star icon974
watch icon47

103
104
105
106
107
108
109
110
111
112
},
// Check MySQL, version
function(asyncCallback) {
  try {
    var version = '0.0.0';
    async.retry({ times: 10, interval: CHECKER_INTERVAL }, function(retryCallback) {
      console.log('Try to check MySQL version...');

      var mysqlConfig = {
        host    : userConfig.MYSQL_HOST,
fork icon34
star icon185
watch icon0

47
48
49
50
51
52
53
54
55
getRequestHash (type, payload) {
  return `${type}:${JSON.stringify(payload)}`
}

request (type, payload, _opts = {}, cb) {
  async.retry(_opts.retry || 1, next => {
    this._request(type, payload, _opts, next)
  }, cb)
}
fork icon13
star icon3
watch icon6

5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
*
* // The `retry` function can be used as a stand-alone control flow by passing
* // a callback, as shown below:
*
* // try calling apiMethod 3 times
* async.retry(3, apiMethod, function(err, result) {
*     // do something with the result
* });
*
* // try calling apiMethod 3 times, waiting 200 ms between each retry
fork icon0
star icon2
watch icon1

+ 9 other calls in file

309
310
311
312
313
314
315
316
317
318
                return cb(null, counter.seq);
            },
        );
    };

    async.retry(0, retriable, callback);
};

/**
 * Utility function to create a record in counter before incrementing
fork icon0
star icon0
watch icon1

200
201
202
203
204
205
206
207
208
209
    });
};

module.exports.retry = function (opts, pf) {
    return new Promise(function (resolve, reject) {
        async.retry(
            opts,
            function (callback) {
                pf()
                    .then(function (msg) {
fork icon0
star icon0
watch icon2

+ 3 other calls in file