title: Promise around event-stream mapSync() not working
body: <p>Currently i am trying to create a CSV reader that can handle very large CSV files. I chose for a streaming implementation with the event-stream NPM package.</p>
  <p>I have created a function getNextp() that should return a promise and give me the next piece of data every time i call it.</p>
  <pre><code>&quot;use strict&quot;;
  const fs = require('fs');
  const es = require('event-stream');
  const csv = require('csv-parser');
  
  class CsvFileReader {
    constructor(file) {
      this.file = file;
      this.isStreamReading = false;
      this.stream = undefined;
    }
  
    getNextP() {
      return new Promise( (resolve) =&gt; {
        if (this.isStreamReading === true) {
            this.stream.resume();
        } else {
          this.isStreamReading = true;
    
          // Start reading the stream.
          this.stream = fs.createReadStream(this.file)
          .pipe(csv())
          .pipe(es.mapSync( (row) =&gt; {
  
            this.stream.pause();
            resolve(row);  
          }))
          .on('error', (err) =&gt; {
            console.error('Error while reading file.', err);
          })
          .on(&quot;end&quot;, () =&gt; {
            resolve(undefined);
          })
        }
      });
    }
  }
  </code></pre>
  <p>I call this then with this code.</p>
  <pre><code>const csvFileReader = new CsvFileReader(&quot;small.csv&quot;);
  setInterval( () =&gt; {
    csvFileReader.getNextP().then( (frame) =&gt; {
      console.log(frame);
    })
  }, 1000);
  </code></pre>
  <p>However every time when i try this out i only get the first row and the subsequent rows i do not get. I can not figure out why this it not working. I have tried the same with a good old callback function and then it works without any problem.</p>
  <p><strong>Update:</strong>
  So what i basically want is a function (getNext()) that returns me every time when i call it the next row of the CSV. Some rows can be buffered, but yeah until now i could not figure out how to do this with streams. So if somebody could give me a pointer on how to create a correct getNext() function that would be great.</p>
  <p>I would like to ask if somebody understands what is going wrong here, and ask kindly to share his/hers knowledge.</p>
  <p>Thank you in advance.</p>