ninenines / gun

HTTP/1.1, HTTP/2, Websocket client (and more) for Erlang/OTP.
ISC License
898 stars 231 forks source link

How to let await return error after canceled? #144

Closed tony612 closed 5 years ago

tony612 commented 6 years ago

I want to return an error if :gun:await/2 is called after the HTTP/2 stream is canceled. Is there any way to achieve this? Like getting the canceled status?

essen commented 6 years ago

It should return an {error, Reason} tuple in that case. Doesn't it?

tony612 commented 6 years ago

It doesn't. Now it will wait forever or until timeout.

essen commented 6 years ago

When you say canceled do you mean that you cancel the stream on the client side or that the server cancels the stream?

tony612 commented 6 years ago

On the client side, after calling gun:cancel/2. Of course I know I shouldn't try to send data after canceling, but I want to know the status of the stream in some way.

essen commented 6 years ago

Ah OK it makes more sense then, I thought you meant the server.

I'm not sure it's possible because gun:await only does a receive. On the other hand maybe what we can add is a separate function to query a stream's state so that you can know whether an await call will have chances of succeeding.

tony612 commented 6 years ago

Yeah, I think adding a function will be a good solution so that we don't need to change how gun:await behaves.

essen commented 5 years ago

I've just added gun:stream_info/2 and it will be in 2.0. Closing, thanks!