shutdown

Attribute Macro shutdown 

Source
#[shutdown]
Expand description

Marker attribute for service shutdown hook. Use on a single method within a #[service] impl block. The method runs on shutdown, before channels close.

Note: Can call other services - workers are still running.

#[service]
impl CacheService {
    #[shutdown]
    async fn flush_cache(&self) {
        // Runs on shutdown, can still call other services
        self.db.save_all(&self.cache.read()).await;
    }
}