Comments (10)
Hey kof,
please explain "all functions of object obj". Shouldn't this be an array of functions? Or maybe I am not getting the big picture.
from node-retry.
// wrap all methods of myLibrary object
retry.wrap({retries: 3}, myLibrary);
// wrap only named methods of myLibrary object
retry.wrap({retries: 3}, myLibrary, ['method1', 'method2', 'method3']);
from node-retry.
even better
// wrap all mehtods of myLibrary using default options
retry.wrap(myLibrary);
// wrap all methods of myLibrary object
retry.wrap(myLibrary, {retries: 3});
// wrap only named methods of myLibrary object
retry.wrap(myLibrary, {retries: 3}, ['method1', 'method2', 'method3']);
from node-retry.
function wrap(obj, options, methods) {
if (options instanceof Array) {
methods = options;
options = null;
}
if (!methods) {
methods = Object.keys(obj);
}
methods.forEach(function(method) {
var origin = obj[method];
if (typeof origin != 'function') {
return;
}
obj[method] = function() {
var op = retry.operation(options),
args = Array.prototype.slice.call(arguments),
callback = args.pop();
args.push(function(err) {
if (op.retry(err)) {
return;
}
if (err) {
arguments[0] = op.mainError();
}
callback.apply(this, arguments);
});
op.attempt(function() {
origin.apply(obj, args);
});
};
});
}
from node-retry.
It needs some changes to support all browsers ... but basically thats it.
from node-retry.
I see. Pretty interesting.
If you could also write some tests for it I'd merge a PR for this one.
from node-retry.
What are requirements for the environment? Is this module supposed to be used in browser? Or just node?
from node-retry.
For now it's just supposed to be used out of node, but I am sure it can be used easily in the browser with node-browserify.
from node-retry.
bump!
from node-retry.
Will finish this and merge the related PR.
from node-retry.
Related Issues (20)
- [Feature Request] Add Promise Support HOT 6
- [Feature Request] CLI command support for shell users
- Update npm package version HOT 1
- [Docs] Question about factor
- [Bug] RetryOperation does not free errors correctly, causing "forever" operations to leak memory
- Needs keywords section is package.json HOT 1
- Unable to clear the current running timer and exit the retry loop HOT 4
- operation.reset() is somewhat unintuitive HOT 1
- Retry a http request HOT 1
- Include previous error even if there's a timeout
- It would be useful if the retry function returned the timout number HOT 4
- When is the next release (with changes from master) scheduled to go out to npm? HOT 4
- node-retry retry.operation is being called only once with jest.fn promise reject mocks HOT 1
- PR suggestion: withRetry wrapper HOT 1
- Missing current attempt in callback
- Typescript 4.4 breaking change affect retry HOT 1
- Check for infinity value in `retries` HOT 2
- Is this the way ? HOT 1
- Setting maxTimeout to undefined breaks minTimeout behavior
- Ability to set timeout for each retry?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-retry.