1

I am using fast-csv with node and have the situation of the jobs triggered by the end event starting before the data event stuff has finished.

The slightly-edited code is the following:

      .on("data", record => {

            async.waterfall([
                doOneThing,
                doOtherThing,
                validate,
                updateRecord,
            ], err => {
                do something
            })
        })
        .on("end", () =>{
            async.waterfall([
                updateFailedRecords,
                 enforceFailedStatuses,
                doSomething,
                doSomethingElse
            ], (err) => {
                dosomething
            });
        });

However, the behavior that I am seing is that the functions that are supposed to be executed onEnd (ie, updateFailedRecords) are being triggered before the first section of functions (the final one of which is updateRecord) finishes.

What is the explanation for this behavior, given that the on end functions should start after the data functions are finished. More importantly, how can I achieve the desired behavior?

Thanks!

Dragan
  • 227
  • 3
  • 9

0 Answers0