title: readable.destroy() not emitting both 'close' and 'error' events Node.js
body: <p>I wrote some code that happens to work, but I thought that <code>readable.destroy()</code> (eg, <code>src.destroy()</code>, in my example) is supposed to emit <code>close</code> and <code>error</code> events...</p>
  
  <p>Here's a somewhat minimal example to illustrate my confusion:</p>
  
  <pre><code>const fs = require('fs');
  const src = fs.createReadStream('streaming-example.js');
  const dst = fs.createWriteStream('streaming-example.txt');
  src.pipe(dst);
  src.on('readable', () =&gt; {
    let chunk;
    while (null !== (chunk = src.read())) {
      /**
      * This should cause 'error' and 'close' events to emit
      * @see https://nodejs.org/dist/latest-v11.x/docs/api/stream.html#stream_readable_destroy_error
      */
      src.destroy();
    }
  });
  src.on('close', () =&gt; console.log(`'close' event emitted`));
  src.on('end', () =&gt; console.log(`'end' event emitted`));
  src.on('error', (err) =&gt; console.log(`'error' event emitted`));
  </code></pre>
  
  <p>And here's a sample run of that program:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ node streaming-example.js 
  'close' event emitted
  $
  </code></pre>
  
  <p>(and, it happens to also finish writing to a new file named <code>streaming-example.txt</code>)</p>
  
  <p>If it's not clear, I expected the <code>close</code> and <code>error</code> events to be emitted and in turn to trigger the corresponding callbacks. However, only the <code>close</code> event seems to have been emitted. </p>
  
  <p>What happened to the <code>error</code> event emission?</p>