collapse-decorator
v1.0.0
Published
A decorator / annotation to collapse async promises, to have instead of hundred pending promises only one.
Downloads
2
Readme
Collapse Decorator
A decorator to collapse promises into a single pending promise to be used with async api calls.
Install
npm install collapse-decorator
Usage
import { Collapse } from 'collapse-decorator';
class Example {
@Collapse(1000)
callApi(param) {
return new Promise((resolve, reject) => {
// do something
});
}
}
Custom Hash-Builder
Sometimes it is necessary to use a custom hash builder function, especially if objects are passed as parameters.
import { Collapse } from 'collapse-decorator';
class Example {
@Collapse(1000, options => `${options.secure}/${options.path}`)
callApi(options) {
return new Promise((resolve, reject) => {
// do something
});
}
}
This will create a hash string for an object, this is not supported by the default hash function.