Inmar Inc. Logo

Patience JS

Basic Usage

Make a request using PatienceJS library.

Note: Re-attempts are not enabled unless explicitly called by your application.


Notification will appear after 3 failed AJAX requests.


// Default Retry Options:
{{ { max: 2, interval: 500 } | json }}

// Sample Angular.js code for this request
{{ ctrl.demoRequests.basic.toString() | parseFunctionBody | removeTabs }}

Custom Retry Options

Make a request using retry library with custom options.


4 failing AJAX requests will be made with 1000ms delay betweeen each request.


// Sample Angular.js code for this request
{{ ctrl.demoRequests.customRetry.toString() | parseFunctionBody | removeTabs }}

Retry & Re-attempt

A Re-attempt is a secondary abstraction available via the retry library. It allows you to be notified when the retry strategy fails while the library starts to re-attempt the request at the provided re-attempt interval.

A re-attempt also allows for an optional intervalMultiplicator option. If provided, intervalMultiplicator is an integer by which the interval will be increased after each re-attempt.


After the retry strategy fails, 3 additional AJAX requests will be attempted.


// Default re-attempt configuration:
{{ { max: 2, interval: 1000, intervalMultiplicator: 1 } | json }}

// Sample Angular.js code for this request
{{ ctrl.demoRequests.retryAndReAttempt.toString() | parseFunctionBody | removeTabs }}

Custom Retry & Re-attempt Options

This request will be made using custom retry and custom re-attempt options.


// Sample Angular.js code for this request
{{ ctrl.demoRequests.customRetryAndReAttempt.toString() | parseFunctionBody | removeTabs }}

Strategies

The explicit syntax of the retry library API can feel repetitive if you are using the same type of API calls in several places in your app. For this case, the .addStrategy(strategyName, options) and .runStrategy(strategyName) methods are available.

As outlined in the README.md documentation, strategies allow you to add preset options for: requests, group, retry, and re-attempt.

You can start by adding a strategy with .addStrategy(strategyName, options) method call. Adding strategies can be especially powerful if you use them as an independent abstraction which your application leverages.

You can reuse these strategies by using the .runStrategy(strategyName) rather than the default .run() method to initiate your AJAX call.


// Add a strategy
{{ ctrl.addStrategy.toString() | parseFunctionBody | removeTabs }}

// Call the strategy which will configure your call automatically per the presets
{{ ctrl.demoRequests.customStrategy.toString() | parseFunctionBody | removeTabs }}