1
use std::{fmt::Debug, sync::Arc};
2

            
3
/// he `Id` of an executing task.
4
388611
#[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)]
5
pub struct Id(pub(crate) u64);
6

            
7
/// References a background task.
8
#[derive(Debug)]
9
pub struct Handle<T, E> {
10
    /// The task's id.
11
    pub id: Id,
12

            
13
    pub(crate) receiver: flume::Receiver<Result<T, Arc<E>>>,
14
}
15

            
16
impl<T, E> Handle<T, E>
17
where
18
    T: Send + Sync + 'static,
19
    E: Send + Sync + 'static,
20
{
21
    /// Waits for the job to complete and returns the result.
22
    ///
23
    /// # Errors
24
    ///
25
    /// Returns an error if the job is cancelled.
26
175367
    pub fn receive(self) -> Result<Result<T, Arc<E>>, flume::RecvError> {
27
175367
        self.receiver.recv()
28
175367
    }
29
}