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(&mut self) -> anyhow::Result<()> {
loop {
match self.ws.recv().await {
Ok(msg) => {}, // e.g. send the message to some other actor
Err(err) => return Err(err), // and maybe even notify some "manager" actor
}
}
}
}