Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: fallback function should pass the same parameters as fire #459

Closed
tomkoufakis opened this issue Aug 26, 2020 · 2 comments
Closed
Labels

Comments

@tomkoufakis
Copy link

FEATURE REQUEST:

When configuring a fallback function, the method signature is without parameters. For example:

circuit.fallback(() => { ... });

The fallback function should be able to accept the same parameters as the fire function. The fallback function, when called, should be called with these same parameters.

This will allow for parameters that can mutate the response of the fallback function.

Example usage:

// circuit setup, only called once
circuit.fallback((arg1, arg2, arg3) => {
return arg1 + arg2 + arg3;
});

// called for each request
return circuit.fire(arg1, arg2, arg3).then((response) => {
console.log(JSON.stringify(response));
});

At present, I do not have a good workaround for this.

Node.js Version:

Operating System:

Steps to Produce Error:

@tomkoufakis
Copy link
Author

After looking through the opossum source, it appears this is already supported and just the documentation needs to be updated.

@helio-frota
Copy link
Member

@tomkoufakis feel free to send a PR.

Either way I created a example usage here:
https://github.com/nodeshift-starters/opossum-playground/tree/master/debuglog/core/fallback-parameters

When running npm start it shows:

DBG-CORE 17491: inside the constructor
DBG-CORE 17491: sets timeout to 10000
DBG-CORE 17491: sets resetTimeout to 30000
DBG-CORE 17491: creates new semaphore with capacity 9007199254740991
DBG-STATUS 17491: status created
DBG-CORE 17491: called fire function with args 20000,1,2,3   <---------
DBG-CORE 17491: fire event emitted
DBG-SEMAPHORE 17491: semaphore counter 9007199254740991
DBG-SEMAPHORE 17491: semaphore released
DBG-CORE 17491: timeout event emitted
DBG-CORE 17491: failure event emitted
DBG-CORE 17491: open event emitted
Sorry, out of service right now. But your parameters are: 20000, 1, 2 and 3    <---------
DBG-CORE 17491: fallback event emitted
fires 1 fallbacks 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants