From bc60f009ad29ca2bb68e368d41a0bc828278a272 Mon Sep 17 00:00:00 2001 From: Zwb Date: Sun, 21 Aug 2016 10:07:10 +0800 Subject: [PATCH] doc: fix onReadable reentry after unshift called In example parseHeader, stream listen **readable** event, if call stream.unshift(buf) before stream.removeListener('readable', onReadable), readable event will be emited before removeListener, so callback will not been called correctlly. After change to ```js stream.removeListener('error', callback); stream.removeListener('readable', onReadable); if (buf.length) stream.unshift(buf); ``` It solves this problem. --- doc/api/stream.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index c86a5c22e6e3ba..125f892f9cec3e 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -963,10 +963,10 @@ function parseHeader(stream, callback) { header += split.shift(); const remaining = split.join('\n\n'); const buf = Buffer.from(remaining, 'utf8'); - if (buf.length) - stream.unshift(buf); stream.removeListener('error', callback); stream.removeListener('readable', onReadable); + if (buf.length) + stream.unshift(buf); // now the body of the message can be read from the stream. callback(null, header, stream); } else {