Skip to content

Instantly share code, notes, and snippets.

@mandolyte
Created December 8, 2019 12:55
Show Gist options
  • Save mandolyte/6eaa9e43f3dd45f544f2048275e2dfd3 to your computer and use it in GitHub Desktop.
Save mandolyte/6eaa9e43f3dd45f544f2048275e2dfd3 to your computer and use it in GitHub Desktop.
De-asynchronize does not work...
$ cat read3.mjs
import csv from "fast-csv";
let expected = [
['Col1','Col2','Col3'],
['1.1','1.2','1.3'],
['2.1','2.2','2.3'],
];
let input = `Col1,Col2,Col3
1.1,1.2,1.3
2.1,2.2,2.3
`;
const doasync = async _ => {
let rows = [];
await csv.parseString(input,{ headers: false })
.on("data", row => rows.push(row) )
.on("end", rowcount => { console.log(`# rows= ${rowcount}`) } )
return rows;
}
let rows = doasync().then(ar => {console.log("then:",ar)});
console.log("rows=",rows);
$ alias nx
alias nx='node --experimental-modules'
$ nx read3.mjs
(node:7896) ExperimentalWarning: The ESM module loader is experimental.
rows= Promise { <pending> }
then: []
# rows= 3
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment