mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
improve heartbeat with run_interval
This commit is contained in:
parent
fb32a7d600
commit
b1e5cef4b5
@ -193,7 +193,7 @@ impl WsChatSession {
|
||||
///
|
||||
/// also this method check heartbeats from client
|
||||
fn hb(&self, ctx: &mut ws::WebsocketContext<Self, WsChatSessionState>) {
|
||||
ctx.run_later(Duration::new(1, 0), |act, ctx| {
|
||||
ctx.run_interval(Duration::new(1, 0), |act, ctx| {
|
||||
// check client heartbeats
|
||||
if Instant::now().duration_since(act.hb) > Duration::new(10, 0) {
|
||||
// heartbeat timed out
|
||||
@ -209,9 +209,6 @@ impl WsChatSession {
|
||||
}
|
||||
|
||||
ctx.ping("");
|
||||
|
||||
// if we can not send message to sink, sink is closed (disconnected)
|
||||
act.hb(ctx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ impl ChatSession {
|
||||
///
|
||||
/// also this method check heartbeats from client
|
||||
fn hb(&self, ctx: &mut Context<Self>) {
|
||||
ctx.run_later(Duration::new(1, 0), |act, ctx| {
|
||||
ctx.run_interval(Duration::new(1, 0), |act, ctx| {
|
||||
// check client heartbeats
|
||||
if Instant::now().duration_since(act.hb) > Duration::new(10, 0) {
|
||||
// heartbeat timed out
|
||||
@ -164,7 +164,6 @@ impl ChatSession {
|
||||
|
||||
act.framed.write(ChatResponse::Ping);
|
||||
// if we can not send message to sink, sink is closed (disconnected)
|
||||
act.hb(ctx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user