Having a problem just connecting with drizzle
Howdy, I just found out about drizzle and thought I might give it a try, but unfortunately I'm having trouble just getting the example working from the documentation.
I've created this sample file:
Then compiled it into JS like this:
Then ran it like this:
The execution order is wrong, and the program just hangs at the end rather than exiting cleanly.
Here's the output:
Any ideas what I'm doing wrong?
4 Replies
You're doing everything correct.
Firstly, the order is not wrong, it's how event loop works in JS. When you invoke an async function, it runs asynchronously to the main thread, so
console.log('after main')
will run in parallel with the main()
function execution.
Secondly, the program is hanging because the event loop isn't empty. That's because you didn't close the DB connection before exit. You should do it either at the end of the main()
function, or in the main().then(...)
callback, so that it's invoked after the function execution is completed.
Also, ideally you should wrap your main()
function invocation in a try-catch block, or add a .catch()
clause, to avoid uncaught promise rejections.wow
i'm a dolt
thank you
np!
yeah this is just a test, not an actual app so i was trying to get quick and dirty success