Hi,

I am looking into implementing my own Readable (by 
following 
https://nodejs.org/docs/v7.9.0/api/stream.html#stream_new_stream_readable_options).
 
The documentation is a bit unclear to me in one point: if the EOS (end of 
stream) is reached, I should call this.push(null), however do I also have 
to check if the last call to push returned false and then not signal EOS?

My stream basically looks like this:

const readable = new Readable({
    read: function () {
        try {
            let chunk: string;
            let canPush = true;

            // Push all chunks as long as we can push and as long as
            // the underlying reader returns strings to us
            while (canPush && typeof (chunk = reader.read()) === 'string') {
                canPush = this.push(chunk);
            }

            // Signal EOS by pushing NULL
            if (typeof chunk !== 'string') {
                this.push(null);
            }
        } catch (error) {
            this.emit('error', error);
        }
    }
});

In this case I am happily calling this.push(null) even though maybe the 
last push signald I should wait?

Thanks for feedback,
Ben
. 

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/2509363d-8c32-4142-9493-6e68562419bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to