1
use std::fmt::Debug;
2
use std::sync::Arc;
3

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

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

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

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