Attribute Macro vin_macros::task

source ·
#[task]
Expand description

Generates a [vin]-managed [tokio] task. It’s a specialized actor with no handler that runs some piece of code until it’s completed or [vin] has shutdown.

Example

 
 
#[vin::task]
struct WebsocketSession {
    ws: WebSocket,
}
 
#[async_trait]
impl TaskActor for WebsocketSession {
    async fn task(&self, ctx: Self::Context) -> anyhow::Result<()> {
        loop {
            let msg = self.ws.recv().await?;
            /* do something */
        }
    }
}