backoff-promise

WebJar for backoff-promise

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

backoff-promise
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

backoff-promise
WebJar for backoff-promise
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/redgeoff/backoff-promise

Download backoff-promise

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/backoff-promise/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>backoff-promise</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/backoff-promise/
implementation 'org.webjars.npm:backoff-promise:0.0.3'
// https://jarcasting.com/artifacts/org.webjars.npm/backoff-promise/
implementation ("org.webjars.npm:backoff-promise:0.0.3")
'org.webjars.npm:backoff-promise:jar:0.0.3'
<dependency org="org.webjars.npm" name="backoff-promise" rev="0.0.3">
  <artifact name="backoff-promise" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='backoff-promise', version='0.0.3')
)
libraryDependencies += "org.webjars.npm" % "backoff-promise" % "0.0.3"
[org.webjars.npm/backoff-promise "0.0.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : bluebird jar [3.5.0,4)
org.webjars.npm : sporks jar [0.0.4]

Project Modules

There are no modules declared in this project.

backoff-promise

Greenkeeper badge Circle CI

An exponential backoff for promises

Example 1

var i = 0,
  Backoff = require('backoff-promise'),
  backoff = new Backoff();

var myPromise = function () {
  return new Promise(function (resolve, reject) {
    if (i++ < 5) {
      reject(new Error('transient-error'));
    } else {
      resolve('foo');
    }
  });
};

return backoff.run(function () {
  return myPromise();
});

Example 2: Different types of errors

var i = 0,
  Backoff = require('backoff-promise'),
  backoff = new Backoff();

var myPromise = function () {
  return new Promise(function (resolve, reject) {
    if (i++ < 3) {
      reject(new Error('transient-error'));
    } else {
      reject(new Error('permanent-error'));
    }
  });
};

var shouldRetry = function (err) {
  // Permanent error? If so, then stop retrying
  if (err.message === 'permanent-error') {
    throw err;
  }
};

return backoff.run(function () {
  return myPromise();
}, shouldRetry).catch(function (err) {
  // err.message = 'transient-error'
});

API

var backoff = Backoff(startingRetryAfterMSecs, maxRetryAfterMSecs, backoffFactor, maxRetries)

Versions

Version
0.0.3