Skip to main content

websocket

Attribute Macro websocket 

Source
#[websocket]
Expand description

Declares a WebSocket endpoint.

The handler takes a WebSocket parameter (the upgrade handle) and returns tork::Result<()>. Other parameters are path parameters or dependencies, resolved before the upgrade. Attributes: path (first), summary, description, tags.

§Example

#[websocket("/ws")]
pub async fn echo(socket: WebSocket) -> tork::Result<()> {
    let mut socket = socket.accept().await?;
    while let Some(message) = socket.recv().await? { /* ... */ }
    Ok(())
}