Skip to content

Commit b60cf8d

Browse files
anishknycharmander
andauthored
Welcome: Wrap await code in async IIFE (#87)
* Welcome: Wrap await code in async IIFE * Update content/welcome.mdx Co-authored-by: Charmander <~@charmander.me> Co-authored-by: Charmander <~@charmander.me>
1 parent 64dacfb commit b60cf8d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

content/welcome.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ This is the simplest possible way to connect, query, and disconnect with async/a
3434
const { Client } = require('pg')
3535
const client = new Client()
3636

37-
await client.connect()
37+
;(async () => {
38+
await client.connect()
3839

39-
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
40-
console.log(res.rows[0].message) // Hello world!
41-
await client.end()
40+
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
41+
console.log(res.rows[0].message) // Hello world!
42+
await client.end()
43+
})()
4244
```
4345

4446
And here's the same thing with callbacks:

0 commit comments

Comments
 (0)