websockets-rs / rust-websocket

A WebSocket (RFC6455) library written in Rust
http://websockets-rs.github.io/rust-websocket/
MIT License
1.55k stars 223 forks source link

Async client example: Don't close twice #244

Closed najamelan closed 5 years ago

najamelan commented 5 years ago

As far as i can tell, the server doesn't initiate the close handshake, so the client should just consider the handshake finished when it receives the acknowledgment and probably just wait for the server to close the underlying connection.

This stops if from trying to start a second close handshake.

It's not exactly clear to me how this avoids dropping the underlying connection before the server closes it now???

There is also a warning:

warning: unused `futures::stream::Select` in tuple element 0 that must be used

  --> examples/async-client.rs:67:2
   |
67 |     runtime.block_on(runner).unwrap();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_must_use)]` on by default
   = note: streams do nothing unless polled

Given how convoluted types get here, I haven't exactly bothered getting to the bottom of this warning.

I think some extra comments would be nice in example code.

jpoles1 commented 5 years ago

As far as I can tell, this warning can be fixed by just assigning that line to a variable: let _runtime_result = runtime.block_on(runner).unwrap();

Also, I definitely second better documentation on this example, had a hard time figuring it all out. Would be happy to try and work on some documentation either after this PR is merged, or in a separate PR.