-
Notifications
You must be signed in to change notification settings - Fork 145
Description
Hello,
I have been trying the following scenario :
var resource = open()
var s = _(function(push, next) {
..use resource to push elements and _.nil when resource is empty ..
})
.consume(function(err, x, push, next) {
if (err === null) {
push(err);
next();
}
else if (x === _.nil) {
resource.close();
push(null, x);
}
else {
push(null,x);
}
})
I open a resource, consume from it, and wait for _.nil to close the resource.
This works well if I consume all the tokens with
s.resume();
now if i do
s.take(10).resume();
The resource is never closed, because take seem to send _.nil downstream but not inform upstream that they will not be pulled from again.
You might say that I could close the resource by catching the _.nil after take(10) but this is not what I want to do because I do not want the downstream code to have a reference to the resource.
Would it make sense to have back-propagation of _.nil or a mechanism to inform upstream streams that they will not be pulled from again ?
In node.js streams, when you do
s1.pipe(s2)
when s2 sends a 'close' event, s1 automatically unpipes s2 for example and you have a way to detect that nothing will be pulled again.
https://github.com/joyent/node/blob/master/lib/_stream_readable.js#L568