Skip to content

This module wraps a function with retry functionality by passing a timeout. So the function will be more tolerant.

License

Notifications You must be signed in to change notification settings

adrai/tolerance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The world needs more TOLERANCE!!!

Introduction

Build Status Actions

Tolerance is a node.js module that wraps a function with retry functionality by passing a timeout. So the function will be more tolerant.

You can use it for example if you want to connect to a database that is not running immediately...

Installation

$ npm install tolerance

Usage

var tolerate = require('tolerance');

tolerate(
	function(callback) {
		db.connect(callback);
	},
	1500,
	function(err, res) {
		// If the db comes up after 800 ms
		// this callback will be called as the connection
		// would have been established immediately.
		//
		// If the db does not come up within the 1500 ms
		// this callback will be called with the appropriate error.
		//
		// In the background 'tolerance' will retry to connect to the db.
	}
);

Use own retry indication

var tolerate = require('tolerance');

tolerate(
	function(callback) {
		db.connect(callback);
	},
	1500,
	function(err) { // should return true if you want to trigger a retry...
		if (err === 'not reached') {
			return true;
		} else {
			return false;
		}
	},
	function(err, res) {
		// If the db comes up after 800 ms
		// this callback will be called as the connection
		// would have been established immediately.
		//
		// If the db does not come up within the 1500 ms
		// this callback will be called with the appropriate error.
		//
		// In the background 'tolerance' will retry to connect to the db.
	}
);

About

This module wraps a function with retry functionality by passing a timeout. So the function will be more tolerant.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published