#2695·axum

WebSocket::try_recv

Author: BaderBCCreated Apr 2, 2024Updated Jun 6, 2026
LabelsC-feature-requestS-blockedA-axum

Feature Request

Motivation

WebSocket::recv blocks the runtime, causing it to wait for a new message. Consequently, when I share Arc<Mutex<WebSocket>> between threads, all threads are blocked until the client sends a message, which would release the block temporarily by triggering a new loop iteration.

Proposal

I propose implementing WebSocket::try_recv, which would give instant feedback, whether there is a message received from client or not.

Alternatives

I have no idea how to solve this problem alternatively.