delayed-stream
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Delayed-stream is a Node.js module that provides functionality for buffering events from a stream until you are ready to handle them. This can be beneficial in cases where events are fired faster than they can be handled, thus preventing data loss and maintaining system stability.
Using delayed-stream is straightforward and intuitive. To start with, you'll need to install it using npm:
npm install delayed-stream
Then, simply require the module and use it in your code. For example, consider the case of an HTTP echo server delaying its response by 1000 milliseconds:
var DelayedStream = require('delayed-stream');
var http = require('http');
http.createServer(function(req, res) {
var delayed = DelayedStream.create(req);
setTimeout(function() {
res.writeHead(200);
delayed.pipe(res);
}, 1000);
});
Additionally, if you're not using Stream#pipe
, you can manually release the buffered events by calling delayedStream.resume()
:
var delayed = DelayedStream.create(req);
setTimeout(function() {
// Emit all buffered events and resume underlaying source
delayed.resume();
}, 1000);
The documentation for delayed-stream can be found directly within the "readme" file of its GitHub repository. The readme provides a thorough explanation of the module's implementation, usage examples, API descriptions and information on error handling and buffer limits. Comprehensive and detailed, it's a valuable resource for understanding and utilizing delayed-stream effectively.