Skip to content

Commit

Permalink
docs(reference/reply): When using async-await, need return (#4429)
Browse files Browse the repository at this point in the history
* docs(reference/reply): When using async-await, please return the reply object to signal fastify wait for your further response.

* docs(reference/reply): When using async-await, please return the reply object to signal fastify wait for your further response.

* Update docs/Reference/Reply.md

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

* Update docs/Reference/Reply.md

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>

* Apply suggestions from code review

Co-authored-by: Andrey Chalkin <L2jLiga@gmail.com>

* docs: return or await reply when async-await

Co-authored-by: Frazer Smith <frazer.dev@outlook.com>
Co-authored-by: Andrey Chalkin <L2jLiga@gmail.com>
  • Loading branch information
3 people committed Dec 27, 2022
1 parent fc81c70 commit 003eae6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/Reference/Reply.md
Expand Up @@ -674,6 +674,15 @@ fastify.get('/streams', function (request, reply) {
reply.send(stream)
})
```
When using async-await you will need to return or await the reply object:
```js
fastify.get('/streams', async function (request, reply) {
const fs = require('fs')
const stream = fs.createReadStream('some-file', 'utf8')
reply.header('Content-Type', 'application/octet-stream')
return reply.send(stream)
})
```

#### Buffers
<a id="send-buffers"></a>
Expand All @@ -689,6 +698,16 @@ fastify.get('/streams', function (request, reply) {
})
```

When using async-await you will need to return or await the reply object:
```js
const fs = require('fs')
fastify.get('/streams', async function (request, reply) {
fs.readFile('some-file', (err, fileBuffer) => {
reply.send(err || fileBuffer)
})
return reply
})
```
#### Errors
<a id="errors"></a>

Expand Down

0 comments on commit 003eae6

Please sign in to comment.