-1

我不能连续两个流在 node.js 中工作。请参阅以下代码:

var Stream = require('stream');

var stream1 = new Stream;
stream1.readable = true;

var stream2 = new Stream;
stream2.readable = stream2.writable = true;

var stream3 = new Stream;
stream3.readable = stream3.writeable = true;

var i = 0;

stream2.write = function(data){this.emit('data', data)};
stream3.write = function(data){this.emit('data', data)};

setInterval((function() {
stream1.emit('data', String(i++));
}), 100);

//works:
stream1.pipe(stream2).pipe(process.stdout);

//does not work - why???
//stream1.pipe(stream2).pipe(stream3).pipe(process.stdout);

如何让两个流连续工作?

4

2 回答 2

1

你会觉得很愚蠢,这是一个拼写错误:

stream2.readable = stream2.writable = true;
stream3.readable = stream3.writeable = true;  

看到区别,一个额外estream3.writable

于 2013-03-08T16:01:06.897 回答
0

尝试async(或来自nmpjs.com) - 最流行的 Node.js 模块,用于使用示例和 wiki 处理异步 JavaScript。

于 2013-03-08T15:08:19.950 回答