seal-droddel v1.0.1
seal-droddel
Serialize asynchronous calls.
Installation
$ npm install seal-droddelQuick start
First you need to add a reference to seal-droddel within your application.
const droddel = require('seal-droddel');To actually throttle a function, call droddel and hand over the function
that shall be throttled.
E.g., if you want to serialize read access to a file, hand over a function
that does the actual fs.readFile call and return its result using a
callback:
const throttledRead = droddel((callback) => {
fs.readFile('/etc/passwd', callback);
});To then read the file, simply call throttledRead:
throttledRead((err, data) => {
// ...
});If you call throttledRead while it is already being run, the new call gets
delayed.
Referencing this
If you need to access this from within the function that shall be
throttled, call the throttledRead function using call and provide the
object that you want to use as this.
E.g., if you want to preserve the outer this, simply hand it over:
throttledRead.call(this, (err, data) => {
// ...
});Running the build
To build this module use roboter.
$ bot9 years ago