mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-11-25 02:51:17 +00:00
Make CancelSafeProcessor impl more concise, format code
This commit is contained in:
parent
c53ae967d5
commit
80044616f9
1 changed files with 28 additions and 21 deletions
41
src/main.rs
41
src/main.rs
|
@ -9,11 +9,18 @@ use awc::Client;
|
|||
use dashmap::{mapref::entry::Entry, DashMap};
|
||||
use futures_core::stream::Stream;
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use std::{collections::HashSet, future::{Future, ready}, path::PathBuf, time::SystemTime, task::{Context, Poll}, pin::Pin};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
future::{ready, Future},
|
||||
path::PathBuf,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
time::SystemTime,
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
sync::oneshot::{Sender, Receiver},
|
||||
sync::oneshot::{Receiver, Sender},
|
||||
};
|
||||
use tracing::{debug, error, info, instrument, Span};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
@ -97,7 +104,11 @@ where
|
|||
}
|
||||
};
|
||||
|
||||
CancelSafeProcessor { path, receiver, fut }
|
||||
CancelSafeProcessor {
|
||||
path,
|
||||
receiver,
|
||||
fut,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,25 +120,21 @@ where
|
|||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
if let Some(ref mut rx) = self.receiver {
|
||||
Pin::new(rx).poll(cx).map(|res| res.map_err(|_| UploadError::Canceled))
|
||||
Pin::new(rx)
|
||||
.poll(cx)
|
||||
.map(|res| res.map_err(|_| UploadError::Canceled))
|
||||
} else {
|
||||
match Pin::new(&mut self.fut).poll(cx) {
|
||||
Poll::Pending => Poll::Pending,
|
||||
Poll::Ready(res) => {
|
||||
Pin::new(&mut self.fut).poll(cx).map(|res| {
|
||||
let opt = PROCESS_MAP.remove(&self.path);
|
||||
match res {
|
||||
Err(e) => Poll::Ready(Err(e)),
|
||||
Ok(tup) => {
|
||||
res.map(|tup| {
|
||||
if let Some((_, vec)) = opt {
|
||||
for sender in vec {
|
||||
let _ = sender.send(tup.clone());
|
||||
}
|
||||
}
|
||||
Poll::Ready(Ok(tup))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tup
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -533,8 +540,8 @@ async fn process(
|
|||
Ok((details, bytes)) as Result<(Details, web::Bytes), UploadError>
|
||||
};
|
||||
|
||||
let (details, bytes) = CancelSafeProcessor::new(thumbnail_path.clone(), Box::pin(process_fut)).await?;
|
||||
|
||||
let (details, bytes) =
|
||||
CancelSafeProcessor::new(thumbnail_path.clone(), Box::pin(process_fut)).await?;
|
||||
|
||||
return Ok(srv_response(
|
||||
HttpResponse::Ok(),
|
||||
|
|
Loading…
Reference in a new issue