Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(reference/reply): When using async-await, need return #4429

Merged
merged 7 commits into from Dec 27, 2022
20 changes: 20 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 the reply object:
radiorz marked this conversation as resolved.
Show resolved Hide resolved
```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,17 @@ fastify.get('/streams', function (request, reply) {
})
```

When using async-await, please return the reply object to signal fastify wait
for your further response.
radiorz marked this conversation as resolved.
Show resolved Hide resolved
```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