]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/node_modules/retry/example/stop.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / npm-registry-client / node_modules / retry / example / stop.js
1 var retry = require('../lib/retry');
2
3 function attemptAsyncOperation(someInput, cb) {
4   var opts = {
5     retries: 2,
6     factor: 2,
7     minTimeout: 1 * 1000,
8     maxTimeout: 2 * 1000,
9     randomize: true
10   };
11   var operation = retry.operation(opts);
12
13   operation.attempt(function(currentAttempt) {
14     failingAsyncOperation(someInput, function(err, result) {
15
16       if (err && err.message === 'A fatal error') {
17         operation.stop();
18         return cb(err);
19       }
20
21       if (operation.retry(err)) {
22         return;
23       }
24
25       cb(operation.mainError(), operation.errors(), result);
26     });
27   });
28 }
29
30 attemptAsyncOperation('test input', function(err, errors, result) {
31   console.warn('err:');
32   console.log(err);
33
34   console.warn('result:');
35   console.log(result);
36 });
37
38 function failingAsyncOperation(input, cb) {
39   return setImmediate(cb.bind(null, new Error('A fatal error')));
40 }