use anyhow::Result;
use tokio::sync::oneshot;
pub struct TransferCompleteNotification {
pub(crate) status: oneshot::Receiver<Result<()>>,
}
impl TransferCompleteNotification {
pub fn completed() -> Self {
let (tx, rx) = oneshot::channel();
let _ = tx.send(Ok(()));
Self { status: rx }
}
pub fn wait(self) -> Result<()> {
self.status
.blocking_recv()
.map_err(|_| anyhow::anyhow!("Transfer handler dropped before completion"))?
}
}
impl std::future::Future for TransferCompleteNotification {
type Output = Result<()>;
fn poll(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
use std::pin::Pin;
Pin::new(&mut self.status).poll(cx).map(|result| {
result
.map_err(|_| anyhow::anyhow!("Transfer handler dropped before completion"))
.and_then(|r| r)
})
}
}