🐛 Bug Report
repl.send inside an async function has created a lot of headache.
with fastify/fastify-static#110 we have another issue. The issue ist that an error is logged because sendFile doesn't accept a callback or return a promise. The route is fulfilled to undefined before the file was sent. This behaviour doesn't agree with https://github.com/fastify/fastify/blob/master/docs/Routes.md#promise-resolution.
Due to the current implementation every decorator/plugin which calls .send under the hood must provide a callback or promise to the consumer. If they don't the handler can't use async/await and will loose the control over the response.
Expected behavior
In the longer term we change the api.
// the data flow isnt determined by the function return value (koajs be like)
fastify
.get('/', async (request, reply) => {
reply.body = await data()
repl.body = sync()
});
In short term:
Teach and update the docs that you can use only reply.send in async/await if you still return a promise that controls the asynchronous operation.
until send is called
fastify
.get('/', async (request, reply) => {
return op().then(reply.send)
});
or we recommend to not use rely.send at all in async functions
🐛 Bug Report
repl.sendinside an async function has created a lot of headache.with fastify/fastify-static#110 we have another issue. The issue ist that an error is logged because
sendFiledoesn't accept a callback or return a promise. The route is fulfilled toundefinedbefore the file was sent. This behaviour doesn't agree with https://github.com/fastify/fastify/blob/master/docs/Routes.md#promise-resolution.Due to the current implementation every decorator/plugin which calls
.sendunder the hood must provide a callback or promise to the consumer. If they don't the handler can't use async/await and will loose the control over the response.Expected behavior
In the longer term we change the api.
In short term:
Teach and update the docs that you can use only
reply.sendin async/await if you still return a promise that controls the asynchronous operation.or we recommend to not use
rely.sendat all in async functions