mirror of
https://github.com/fafhrd91/actix-net
synced 2025-06-28 16:50:37 +02:00
Disconnect callback accepts owned state
This commit is contained in:
@ -43,7 +43,7 @@ where
|
||||
framed: Framed<T, U>,
|
||||
rx: mpsc::Receiver<Result<Message<<U as Encoder>::Item>, S::Error>>,
|
||||
tx: mpsc::Sender<Result<Message<<U as Encoder>::Item>, S::Error>>,
|
||||
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
|
||||
disconnect: Option<Rc<dyn Fn(St, bool)>>,
|
||||
}
|
||||
|
||||
impl<St, S, T, U> Dispatcher<St, S, T, U>
|
||||
@ -63,7 +63,7 @@ where
|
||||
service: F,
|
||||
sink: Sink<<U as Encoder>::Item>,
|
||||
rx: mpsc::Receiver<Result<Message<<U as Encoder>::Item>, S::Error>>,
|
||||
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
|
||||
disconnect: Option<Rc<dyn Fn(St, bool)>>,
|
||||
) -> Self {
|
||||
let tx = rx.sender();
|
||||
|
||||
@ -245,7 +245,7 @@ where
|
||||
}
|
||||
}
|
||||
if let Some(ref disconnect) = self.disconnect {
|
||||
(&*disconnect)(&mut self.state, true);
|
||||
(&*disconnect)(self.state.clone(), true);
|
||||
}
|
||||
Poll::Ready(Err(self.dispatch_state.take_error()))
|
||||
}
|
||||
@ -265,19 +265,19 @@ where
|
||||
let _ = tx.send(());
|
||||
}
|
||||
if let Some(ref disconnect) = self.disconnect {
|
||||
(&*disconnect)(&mut self.state, false);
|
||||
(&*disconnect)(self.state.clone(), false);
|
||||
}
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
FramedState::FramedError(_) => {
|
||||
if let Some(ref disconnect) = self.disconnect {
|
||||
(&*disconnect)(&mut self.state, true);
|
||||
(&*disconnect)(self.state.clone(), true);
|
||||
}
|
||||
Poll::Ready(Err(self.dispatch_state.take_framed_error()))
|
||||
}
|
||||
FramedState::Stopping => {
|
||||
if let Some(ref disconnect) = self.disconnect {
|
||||
(&*disconnect)(&mut self.state, false);
|
||||
(&*disconnect)(self.state.clone(), false);
|
||||
}
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ impl<St: Clone, Codec> Builder<St, Codec> {
|
||||
|
||||
pub struct ServiceBuilder<St, C, Io, Codec> {
|
||||
connect: C,
|
||||
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
|
||||
disconnect: Option<Rc<dyn Fn(St, bool)>>,
|
||||
_t: PhantomData<(St, Io, Codec)>,
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ where
|
||||
/// Second parameter indicates error occured during disconnect.
|
||||
pub fn disconnect<F, Out>(mut self, disconnect: F) -> Self
|
||||
where
|
||||
F: Fn(&mut St, bool) + 'static,
|
||||
F: Fn(St, bool) + 'static,
|
||||
{
|
||||
self.disconnect = Some(Rc::new(disconnect));
|
||||
self
|
||||
@ -122,7 +122,7 @@ where
|
||||
|
||||
pub struct NewServiceBuilder<St, C, Io, Codec> {
|
||||
connect: C,
|
||||
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
|
||||
disconnect: Option<Rc<dyn Fn(St, bool)>>,
|
||||
_t: PhantomData<(St, Io, Codec)>,
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ where
|
||||
/// Second parameter indicates error occured during disconnect.
|
||||
pub fn disconnect<F>(mut self, disconnect: F) -> Self
|
||||
where
|
||||
F: Fn(&mut St, bool) + 'static,
|
||||
F: Fn(St, bool) + 'static,
|
||||
{
|
||||
self.disconnect = Some(Rc::new(disconnect));
|
||||
self
|
||||
@ -175,7 +175,7 @@ where
|
||||
pub struct FramedService<St, C, T, Io, Codec, Cfg> {
|
||||
connect: C,
|
||||
handler: Rc<T>,
|
||||
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
|
||||
disconnect: Option<Rc<dyn Fn(St, bool)>>,
|
||||
_t: PhantomData<(St, Io, Codec, Cfg)>,
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ where
|
||||
pub struct FramedServiceImpl<St, C, T, Io, Codec> {
|
||||
connect: C,
|
||||
handler: Rc<T>,
|
||||
disconnect: Option<Rc<dyn Fn(&mut St, bool)>>,
|
||||
disconnect: Option<Rc<dyn Fn(St, bool)>>,
|
||||
_t: PhantomData<(St, Io, Codec)>,
|
||||
}
|
||||
|
||||
@ -359,13 +359,13 @@ where
|
||||
Connect(
|
||||
#[pin] C::Future,
|
||||
Rc<T>,
|
||||
Option<Rc<dyn Fn(&mut St, bool)>>,
|
||||
Option<Rc<dyn Fn(St, bool)>>,
|
||||
Option<mpsc::Receiver<ServiceResult<Codec, C::Error>>>,
|
||||
),
|
||||
Handler(
|
||||
#[pin] T::Future,
|
||||
Option<ConnectResult<Io, St, Codec>>,
|
||||
Option<Rc<dyn Fn(&mut St, bool)>>,
|
||||
Option<Rc<dyn Fn(St, bool)>>,
|
||||
Option<mpsc::Receiver<ServiceResult<Codec, C::Error>>>,
|
||||
),
|
||||
Dispatcher(Dispatcher<St, T::Service, Io, Codec>),
|
||||
|
Reference in New Issue
Block a user