diff --git a/websocket-tcp-chat/src/main.rs b/websocket-tcp-chat/src/main.rs index 0c8f1c47..10e1f5d1 100644 --- a/websocket-tcp-chat/src/main.rs +++ b/websocket-tcp-chat/src/main.rs @@ -193,7 +193,7 @@ impl WsChatSession { /// /// also this method check heartbeats from client fn hb(&self, ctx: &mut ws::WebsocketContext) { - 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); }); } } diff --git a/websocket-tcp-chat/src/session.rs b/websocket-tcp-chat/src/session.rs index 48985156..37bd33a9 100644 --- a/websocket-tcp-chat/src/session.rs +++ b/websocket-tcp-chat/src/session.rs @@ -149,7 +149,7 @@ impl ChatSession { /// /// also this method check heartbeats from client fn hb(&self, ctx: &mut Context) { - 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); }); } }