cleanup all the <Uploader as Actor>::Context
s
This commit is contained in:
parent
e95590ef07
commit
b33bb7aa9d
|
@ -82,6 +82,8 @@ impl Actor for Uploader {
|
|||
type Context = ws::WebsocketContext<Self>;
|
||||
}
|
||||
|
||||
type Context = <Uploader as Actor>::Context;
|
||||
|
||||
pub struct UploadedFile {
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
|
@ -141,7 +143,7 @@ impl From<&Error> for ServerMessage {
|
|||
}
|
||||
}
|
||||
|
||||
fn stop_and_flush<T>(_: T, u: &mut Uploader, ctx: &mut <Uploader as Actor>::Context) {
|
||||
fn stop_and_flush<T>(_: T, u: &mut Uploader, ctx: &mut Context) {
|
||||
ctx.stop();
|
||||
if let Some(w) = u.writer.as_mut() {
|
||||
if let Err(e) = w.flush() {
|
||||
|
@ -178,12 +180,12 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Uploader {
|
|||
}
|
||||
}
|
||||
|
||||
fn ack(ctx: &mut <Uploader as Actor>::Context) {
|
||||
fn ack(ctx: &mut Context) {
|
||||
ctx.text("ack");
|
||||
}
|
||||
|
||||
impl Uploader {
|
||||
fn notify_error_and_cleanup(&mut self, e: Error, ctx: &mut <Self as Actor>::Context) {
|
||||
fn notify_error_and_cleanup(&mut self, e: Error, ctx: &mut Context) {
|
||||
error!("{}", e);
|
||||
ctx.text(serde_json::to_string(&ServerMessage::from(&e)).unwrap());
|
||||
ctx.close(Some(ws::CloseReason {
|
||||
|
@ -196,7 +198,7 @@ impl Uploader {
|
|||
fn handle_message(
|
||||
&mut self,
|
||||
msg: ws::Message,
|
||||
ctx: &mut <Self as Actor>::Context,
|
||||
ctx: &mut Context,
|
||||
) -> Result<bool, Error> {
|
||||
trace!("Websocket message: {:?}", msg);
|
||||
match msg {
|
||||
|
@ -273,7 +275,7 @@ impl Uploader {
|
|||
.await
|
||||
.add_file(storage_filename, stored_file)
|
||||
.await
|
||||
}).map(|res, u: &mut Self, ctx: &mut <Self as Actor>::Context| {
|
||||
}).map(|res, u: &mut Self, ctx: &mut Context| {
|
||||
match res {
|
||||
Ok(Ok(())) => ctx.text(serde_json::to_string(&ServerMessage::Ready { code: u.storage_filename.clone() }).unwrap()),
|
||||
Ok(Err(size)) => u.notify_error_and_cleanup(Error::TooBig(size), ctx),
|
||||
|
@ -322,7 +324,7 @@ impl Uploader {
|
|||
}
|
||||
}
|
||||
|
||||
fn cleanup_after_error(&mut self, ctx: &mut <Self as Actor>::Context) {
|
||||
fn cleanup_after_error(&mut self, ctx: &mut Context) {
|
||||
info!(
|
||||
"Cleaning up after failed upload of {}",
|
||||
self.storage_filename
|
||||
|
|
Loading…
Reference in a new issue