This commit is contained in:
orion 2024-05-03 14:28:23 -05:00
parent 8e842feeef
commit 499eb82986
Signed by: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 9 additions and 7 deletions

View File

@ -12,7 +12,7 @@ export const makeImpl = (c) => () => {
const parser = new ParserWithColumns(c); const parser = new ParserWithColumns(c);
parser.once("readable", () => { parser.once("readable", () => {
parser.columns = parser.read(); parser.columns = parser.read();
parser.emit('columns', parser.columns) parser.emit("columns", parser.columns);
}); });
return parser; return parser;
}; };

View File

@ -127,10 +127,12 @@ foreach stream cb = do
pure $ Canceler $ const $ liftEffect stop pure $ Canceler $ const $ liftEffect stop
liftAff $ makeAff \res -> do liftAff $ makeAff \res -> do
removeDataListener <- flip (Event.on dataH) stream \row -> launchAff_ $ delay (wrap 0.0) <* liftEffect do removeDataListener <- flip (Event.on dataH) stream \row -> launchAff_ $ delay (wrap 0.0) <* liftEffect
( flip catchError (res <<< Left) do
cols <- liftMaybe (error "unreachable") =<< getOrInitColumnsMap stream cols <- liftMaybe (error "unreachable") =<< getOrInitColumnsMap stream
record <- liftEither $ lmap (error <<< show) $ runExcept $ readCSVRecord @r @rl cols row record <- liftEither $ lmap (error <<< show) $ runExcept $ readCSVRecord @r @rl cols row
launchAff_ $ flip catchError (liftEffect <<< res <<< Left) (unlift $ cb record) launchAff_ $ flip catchError (liftEffect <<< res <<< Left) (unlift $ cb record)
)
removeEndListener <- flip (Event.once Stream.endH) stream (res $ Right unit) removeEndListener <- flip (Event.once Stream.endH) stream (res $ Right unit)
removeErrorListener <- flip (Event.on Stream.errorH) stream (res <<< Left) removeErrorListener <- flip (Event.on Stream.errorH) stream (res <<< Left)