I understand from a couple of similar questions that to use async await at the top level, it is necessary to wrap up anonymous functions.
I'm trying to initialize several database connections, and can't get the syntax right.
I've tried the following:
let dbs = Promise.all(async () => {
await sqlite3.open("./db1.sqlite", { Promise }),
await sqlite3.open("./db2.sqlite", { Promise })
}
)
let [db_in, db_out] = dbs
which fails with:
evalmachine.<anonymous>:16
let [db_in, db_out] = dbs
^
TypeError: dbs is not iterable
And
async function init_dbs() {
const [db_in, db_out, abstract_queue] = await Promise.all([
sqlite3.open("./db1.sqlite", { Promise }),
sqlite3.open("./db2.sqlite", { Promise })
]);
let result = await [db_in,db_out]
}
const [db_in, db_out] = init_dbs().then(() => [db_in, db_out])
which returns
evalmachine.<anonymous>:44
const [db_in, db_out] = init_dbs().then(() => [db_in, db_out])
^
TypeError: init_dbs(...).then is not a function or its return value is not iterable
What's the right syntax for this?