fred
fred
DDeno
Created by fred on 3/8/2024 in #help
deno oak : howto force reply immediatly, and process the request later ?
Bonjour, My server needs to reply an ACK (200 OK) for each request. If it did not, the client dies. 😱 After the ACK reply, I try my best to process the request. Sometimes it works, sometimes it fails. We don't care.
async function try_doing_something_with(my_req: Request, my_cible: string): void {
// ...
await sleep(555);
}

router.get("/:cible/simple", async (ctx) => {
ctx.response.status = 200;
ctx.response.type = "text/plain";
ctx.response.body = "don't panic, process is started";
// send reply now.
try_doing_something_with(ctx.request, ctx.params.cible);
});
async function try_doing_something_with(my_req: Request, my_cible: string): void {
// ...
await sleep(555);
}

router.get("/:cible/simple", async (ctx) => {
ctx.response.status = 200;
ctx.response.type = "text/plain";
ctx.response.body = "don't panic, process is started";
// send reply now.
try_doing_something_with(ctx.request, ctx.params.cible);
});
In the oak documentation, I saw that I should register a middleware and use next() to call it. But I can't figure how to code this practically. I'm also afraid that the data in ctx.request could be unavailable. Because when my reply is sent, my socket is closed, so obviously my context should be destroyed from memory. Thank you for your help and links. 🙂
4 replies