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
Await all "response" listeners to finish #569
Comments
Hi 👋
That happens because you use
Am I reading this right: the process exists before the "response" listeners you have are called? The response event is emitted as soon as the response starts streaming. If your logic doesn't get called until the response finishes, I suspect you are doing something async in the response listener. Is that the case? Overall, I don't think we should provide any means to await events as that's outside of tihs library's promise. But I'd like to learn more about your use case and see if I have something to recommend to achieve it. |
Right now, we just emit the response event:
This means if the listener to that event is async, the process will not await its execution. We can use the There are a couple of downsides to using it:
|
hi @kettanaito thanks for your answer!
below is an example to test the issue. when you run this, you'll see the "response completed" line prints before the
|
Yeah I think we have to await the response listeners. If you have none or all are sync, you pay nothing. If it's async, you expect that async to resolve within the request promise anyway. Should be a matter of adding tests and swapping this.emitter.emit with emitAsync. |
hi, we have code that looks like this:
if there is an error with one of the requests, the process ends
in this scenario, we would like to make sure that responses are logged. however, there may be a small delay and the process terminates before the response is logged.
is there a way to wait until the interceptor has invoked the
response
hook for all pending requests?The text was updated successfully, but these errors were encountered: