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

question: How to execute code after the response is sent to client #1396

Open
victor-murillo-deel opened this issue May 31, 2024 · 2 comments
Labels
type: question Questions about the usage of the library.

Comments

@victor-murillo-deel
Copy link

I'd like to execute some logic after my controller returns a response. Since this logic does not impact the result, I'd like to return first, so the client can receive the response asap, and then run this additional logic Something like https://stackoverflow.com/questions/16180502/why-can-i-execute-code-after-res-send

The problem: It's not clear to me how to achieve this with this library

@victor-murillo-deel victor-murillo-deel added the type: question Questions about the usage of the library. label May 31, 2024
@MdTosif
Copy link

MdTosif commented Jul 15, 2024

did you tried @res decorator? you can use res.send like you would do in the express and then run the extra code.

@bugfloyd
Copy link

bugfloyd commented Aug 6, 2024

You can simply move the side-logic execution to a promise but don't await for it while responding the HTTP request. You don't need to work directly with the request object to send the response. After invoking the promise, just return the value as you do normally so routing-controller handles it. Later Node.js continues executing your promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Questions about the usage of the library.
Development

No branches or pull requests

3 participants