adaltas / node-stream-transform

Object transformations implementing the Node.js `stream.Transform` API
https://csv.js.org/transform/
49 stars 13 forks source link

In asynchronous mode, transform doesn't run if there is no following pipe. #14

Closed ate-f closed 9 years ago

ate-f commented 9 years ago

I have a transformer:

transform(function(record, callback) {
 //some code that returns a promise
 promise.then(function(){callback(null,x){);
}
 // a pipe:
request
 .get(fileUrl)
 .pipe(parser)
 .pipe(transformer)

while I might be misusing the transformer somewhat, I would expect this to work. However at the moment processing stops after 15 transforms. If I add .pipe(process.stdout); the pipe continues as it should.

wdavidw commented 9 years ago

You're right, the reason why it hangs is because no one is consuming the stream. This is because the module is a "stream.Transformable" and is expected to seat between a "stream.Writable" and a "stream.Readable".

In commit a404f24131b7b74949dda253615462f88ebd4486, I've just added a "consume" option which shall fix you're pb