1.0.0 • Published 11 years ago
stream-compute v1.0.0
stream-compute
Combines several streams of events, and computes a value every time one changes
Install
npm install --save stream-computeAPI
streamCompute(inputs, compute(data,cb))
inputsis an array of strings that are the names of the dependencies for this computationcompute(data, cb)is the function used for performing the computation. -dataAn object that contains keys that correspond to theinputsarray that was passed in. The keys contain the last known value of that dependency. Computing only starts once all inputs have sent at least one value. -cb(err, result)is the callback which should be called after the computation has finished
The function returns an object that contains the following keys:
inputwhich is a map of Writable streams which are populated by the list ofinputsoutputa Readable stream which has the results of computations
Example
var streamArray = require("stream-array");
var intervalStream = require("interval-stream");
var stdout = require("stdout");
var streamCompute = require("stream-compute");
var greeter = make_greeter();
var messages = streamArray(["Hello", "What's up", "Greetz"]);
var names = streamArray(["Alice", "Bob", "Eve"]);
greeter.output.pipe(stdout("Output:"));
messages.pipe(intervalStream(200)).pipe(greeter.input.message);
names.pipe(intervalStream(300)).pipe(greeter.input.name);
function make_greeter() {
return streamCompute(["message", "name"], function(data, cb) {
var name = data.name;
var message = data.message;
var result = {
message: "Hey, " + name + ": " + message
};
cb(null, result);
});
}1.0.0
11 years ago