1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use anyhow::Error;
use crb_core::JoinHandle;
use futures::Future;

pub struct TypelessTask {
    handle: JoinHandle<()>,
}

impl Drop for TypelessTask {
    fn drop(&mut self) {
        self.handle.abort();
    }
}

impl TypelessTask {
    pub fn spawn<T>(fut: T) -> Self
    where
        T: Future<Output = Result<(), Error>> + Send + 'static,
    {
        let handle = crb_core::spawn(async {
            if let Err(err) = fut.await {
                log::error!("The service task has failed: {}", err);
            }
        });
        Self { handle }
    }
}