All Projects → abacaj → Resolutejs

abacaj / Resolutejs

Licence: mit
Finally get to retry during a Promise operation (works in modern browsers as well as nodejs), zero dependencies.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Resolutejs

Cv4pve Api Java
Proxmox VE Client API JAVA
Stars: ✭ 17 (-26.09%)
Mutual labels:  api
Ripple Lib
A JavaScript API for interacting with the XRP Ledger in Node.js and the browser
Stars: ✭ 899 (+3808.7%)
Mutual labels:  api
Alpaca Trade Api Python
Python client for Alpaca's trade API
Stars: ✭ 912 (+3865.22%)
Mutual labels:  api
Wykop Es6
Wykop.pl API library
Stars: ✭ 17 (-26.09%)
Mutual labels:  api
Miteb Frontend
Online portal to book events and rooms for clubs of MIT, Manipal ✨
Stars: ✭ 18 (-21.74%)
Mutual labels:  api
Movement
Movement is an easier, simpler way to explore and use NIEM. Want to join the Movement and contribute to it? Start here.
Stars: ✭ 19 (-17.39%)
Mutual labels:  api
Orbit Db Http Api
A HTTP API Server for the OrbitDB distributed peer-to-peer database
Stars: ✭ 17 (-26.09%)
Mutual labels:  api
Geocoder
🌎 GoLang package that provides an easy way to use the Google Geocoding API
Stars: ✭ 23 (+0%)
Mutual labels:  api
Api schema
DSL for describing APIs and generate swagger json
Stars: ✭ 18 (-21.74%)
Mutual labels:  api
Web Dev Resources Wiki
A collection of my favorite resources for web development, design, and frameworks
Stars: ✭ 22 (-4.35%)
Mutual labels:  api
Atbapi
Sane API for bus data in Trondheim, Norway
Stars: ✭ 17 (-26.09%)
Mutual labels:  api
Httr
httr: a friendly http package for R
Stars: ✭ 897 (+3800%)
Mutual labels:  api
Slack
🎉✨ Slack API client for Node and browsers.
Stars: ✭ 903 (+3826.09%)
Mutual labels:  api
Django rest example
Django/DRF rest application example.
Stars: ✭ 17 (-26.09%)
Mutual labels:  api
Cortex4py
Python API Client for Cortex
Stars: ✭ 22 (-4.35%)
Mutual labels:  api
Hacker News Api
JavaScript wrapper for the official Hacker News API
Stars: ✭ 17 (-26.09%)
Mutual labels:  api
Minapp
重新定义微信小程序的开发
Stars: ✭ 902 (+3821.74%)
Mutual labels:  api
Swaddle
Automagically create API clients/wrappers in JavaScript
Stars: ✭ 23 (+0%)
Mutual labels:  api
Forge Server Utils
Tools for accessing Autodesk Forge APIs from modern Node.js apps.
Stars: ✭ 23 (+0%)
Mutual labels:  api
Http.cat
🐱 HTTP Cats API
Stars: ✭ 898 (+3804.35%)
Mutual labels:  api

resolute.js

Determined, and unwavering.

Github Releases (by Release) GitHub stars

Finally get to retry during a Promise operation (works in modern browsers as well as node.js), zero dependencies.

It includes a very basic but reliable retry mechanism for a Promise operation.

Minimal requirements: 3kb unminified / 0 dependencies.

Use Cases

  • Database retry
  • API retry
  • Anything...

Packages

NPM - resolutejs

Usage

Download resolute.js from Github Releases (by Release), create a new instance as shown below and optionally provide a callback that is executed every retry, which gives you the current retry count.

Node.js

var Resolute = require("./resolute");

var somePromiseOperation = function() {
    return new Promise(function(resolve, reject) {
        // Make it fail...
        if (err) return reject(err);
        resolve("success");
    });
};

var resolute_options = {
    // Reference to your Promise function, note: this Promise will always fail.
    operation: somePromiseOperation,
    // Maximum number of times to attempt
    maxRetry: 5,
    // Delay between retries in milliseconds
    delay: 2000
};

var resolute_callback = function(retryCount) {
    console.log(retryCount);
};

var resolute = new Resolute(resolute_options, resolute_callback);

// Run the operation stored in options.
resolute.run().then(null).catch(function(err) {
    console.log("failed after trying: " + resolute.maxRetry + " times, with error: " + err);
});

// Pass in a new operation to perform using the same Resolute instance.
resolute.run(somePromiseOperation).then(null).catch(function(err) {
    console.log("failed after trying: " + resolute.maxRetry + " times, with error: " + err);
});

exponential backoff

By passing in the exponential backoff flag resolute will exponentially increase the waiting time between retries.

...

var resolute_options = {
    // Reference to your Promise function, note: this Promise will always fail.
    operation: somePromiseOperation,
    // Maximum number of times to attempt
    maxRetry: 5,
    // Delay between retries in milliseconds
    delay: 2000,
    // exponentially increase wait time between retries
    exponentialBackoff: true, //default false
};

var resolute_callback = function(retryCount, delay) {
    console.log(`Retry ${retryCount} in ${delay} ms`);
};

var resolute = new Resolute(resolute_options, resolute_callback);

// Run the operation stored in options.
resolute.run().then(null).catch(function(err) {
    console.log("failed after trying: " + resolute.maxRetry + " times, with error: " + err);
});

// Pass in a new operation to perform using the same Resolute instance.
resolute.run(somePromiseOperation).then(null).catch(function(err) {
    console.log("failed after trying: " + resolute.maxRetry + " times, with error: " + err);
});

Browser

<script src="resolute.js"></script>
var somePromiseOperation = function() {
    return new Promise(function(resolve, reject) {
        // Make it fail...
        if (err) return reject(err);
        resolve("success");
    });
};

var resolute_options = {
    // Reference to your Promise function, note: this Promise will always fail.
    operation: somePromiseOperation,
    // Maximum number of times to attempt
    maxRetry: 5,
    // Delay between retries in milliseconds
    delay: 2000
};

var resolute_callback = function(retryCount) {
    console.log(retryCount);
};

var resolute = new Resolute(resolute_options, resolute_callback);

// Run the operation stored in options.
resolute.run().then(null).catch(function(err) {
    console.log("failed after trying: " + resolute.maxRetry + " times, with error: " + err);
});

// Pass in a new operation to perform using the same Resolute instance.
resolute.run(somePromiseOperation).then(null).catch(function(err) {
    console.log("failed after trying: " + resolute.maxRetry + " times, with error: " + err);
});

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].