From 499eb829869599d06ffc5909feb715e86663bb86 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Fri, 3 May 2024 14:28:23 -0500 Subject: [PATCH] fix: ?? --- src/Node.Stream.CSV.Parse.js | 2 +- src/Node.Stream.CSV.Parse.purs | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Node.Stream.CSV.Parse.js b/src/Node.Stream.CSV.Parse.js index a8e31a2..6c6cdf5 100644 --- a/src/Node.Stream.CSV.Parse.js +++ b/src/Node.Stream.CSV.Parse.js @@ -12,7 +12,7 @@ export const makeImpl = (c) => () => { const parser = new ParserWithColumns(c); parser.once("readable", () => { parser.columns = parser.read(); - parser.emit('columns', parser.columns) + parser.emit("columns", parser.columns); }); return parser; }; diff --git a/src/Node.Stream.CSV.Parse.purs b/src/Node.Stream.CSV.Parse.purs index ecb3d9d..6412848 100644 --- a/src/Node.Stream.CSV.Parse.purs +++ b/src/Node.Stream.CSV.Parse.purs @@ -122,15 +122,17 @@ foreach stream cb = do $ liftAff $ makeAff \res -> do stop <- flip (Event.once columnsH) stream $ const do - void $ getOrInitColumnsMap stream - res $ Right unit + void $ getOrInitColumnsMap stream + res $ Right unit pure $ Canceler $ const $ liftEffect stop liftAff $ makeAff \res -> do - removeDataListener <- flip (Event.on dataH) stream \row -> launchAff_ $ delay (wrap 0.0) <* liftEffect do - cols <- liftMaybe (error "unreachable") =<< getOrInitColumnsMap stream - record <- liftEither $ lmap (error <<< show) $ runExcept $ readCSVRecord @r @rl cols row - launchAff_ $ flip catchError (liftEffect <<< res <<< Left) (unlift $ cb record) + removeDataListener <- flip (Event.on dataH) stream \row -> launchAff_ $ delay (wrap 0.0) <* liftEffect + ( flip catchError (res <<< Left) do + cols <- liftMaybe (error "unreachable") =<< getOrInitColumnsMap stream + record <- liftEither $ lmap (error <<< show) $ runExcept $ readCSVRecord @r @rl cols row + launchAff_ $ flip catchError (liftEffect <<< res <<< Left) (unlift $ cb record) + ) removeEndListener <- flip (Event.once Stream.endH) stream (res $ Right unit) removeErrorListener <- flip (Event.on Stream.errorH) stream (res <<< Left)