Skip to content

Feature request: Non-blocking WebSocket::read #378

@emilk

Description

@emilk

WebSocket::read is currently blocking. I would love a non-blocking version that tries to read a message, and if there is none, returns immediately.

I want to accomplish something like this:

let socket = …
loop {
    while let Some(msg) = socket.try_read() {
        handle(msg);
    }

    if some_user_input {
        socket.send();
    }}

I can accomplish this using tokio_tungstenite::connect_async and calling split on the resulting stream, but I rather not pull in async and tokio if I can avoid it!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions