1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 02:21:07 +01:00

simple callback

This commit is contained in:
Nikolay Kim 2019-07-02 12:35:27 +06:00
parent 5a62175b6e
commit 922a919572

View File

@ -81,14 +81,9 @@ where
/// Second parameter indicates error occured during disconnect. /// Second parameter indicates error occured during disconnect.
pub fn disconnect<F, Out>(mut self, disconnect: F) -> Self pub fn disconnect<F, Out>(mut self, disconnect: F) -> Self
where where
F: Fn(&mut St, bool) -> Out + 'static, F: Fn(&mut St, bool) + 'static,
Out: IntoFuture,
Out::Future: 'static,
{ {
self.disconnect = Some(Rc::new(move |st, error| { self.disconnect = Some(Rc::new(disconnect));
let fut = disconnect(st, error).into_future();
tokio_current_thread::spawn(fut.map_err(|_| ()).map(|_| ()));
}));
self self
} }
@ -136,16 +131,11 @@ where
/// Callback to execute on disconnect /// Callback to execute on disconnect
/// ///
/// Second parameter indicates error occured during disconnect. /// Second parameter indicates error occured during disconnect.
pub fn disconnect<F, Out>(mut self, disconnect: F) -> Self pub fn disconnect<F>(mut self, disconnect: F) -> Self
where where
F: Fn(&mut St, bool) -> Out + 'static, F: Fn(&mut St, bool) + 'static,
Out: IntoFuture,
Out::Future: 'static,
{ {
self.disconnect = Some(Rc::new(move |st, error| { self.disconnect = Some(Rc::new(disconnect));
let fut = disconnect(st, error).into_future();
tokio_current_thread::spawn(fut.map_err(|_| ()).map(|_| ()));
}));
self self
} }