use crate::async_rt;
use crate::error::{TaskError, ZmqError, ZmqResult};
use futures::channel::oneshot;
pub struct TaskHandle<T> {
stop_channel: oneshot::Sender<()>,
join_handle: async_rt::task::JoinHandle<ZmqResult<T>>,
}
impl<T> TaskHandle<T> {
#[allow(unused)]
pub(crate) fn new(
stop_channel: oneshot::Sender<()>,
join_handle: async_rt::task::JoinHandle<ZmqResult<T>>,
) -> Self {
Self {
stop_channel,
join_handle,
}
}
#[allow(dead_code)]
pub(crate) async fn shutdown(self) -> ZmqResult<T> {
let _ = self.stop_channel.send(());
let join_result = self.join_handle.await.map_err(TaskError::from);
match join_result {
Ok(Ok(ok)) => Ok(ok),
Ok(Err(zmq_err)) => Err(zmq_err),
Err(task_err) => Err(ZmqError::Task(task_err)),
}
}
}