StartHeartBeatWithOption starts heartbeat detection with a custom callback function. interval: the time interval between each heartbeat message. option: a HeartBeatOption struct that contains the custom callback function and message 启动心跳检测(自定义回调)
(interval time.Duration, option *ziface.HeartBeatOption)
| 255 | // option: a HeartBeatOption struct that contains the custom callback function and message |
| 256 | // 启动心跳检测(自定义回调) |
| 257 | func (c *Client) StartHeartBeatWithOption(interval time.Duration, option *ziface.HeartBeatOption) { |
| 258 | // Create a new heartbeat checker with the given interval. |
| 259 | checker := NewHeartbeatChecker(interval) |
| 260 | |
| 261 | // Set the heartbeat checker's callback function and message ID based on the HeartBeatOption struct. |
| 262 | if option != nil { |
| 263 | checker.SetHeartbeatMsgFunc(option.MakeMsg) |
| 264 | checker.SetOnRemoteNotAlive(option.OnRemoteNotAlive) |
| 265 | checker.BindRouter(option.HeartBeatMsgID, option.Router) |
| 266 | } |
| 267 | |
| 268 | // Add the heartbeat checker's route to the client's message handler. |
| 269 | c.AddRouter(checker.MsgID(), checker.Router()) |
| 270 | |
| 271 | // Bind the heartbeat checker to the client's connection. |
| 272 | c.hc = checker |
| 273 | } |
| 274 | |
| 275 | // 保证重复调用Stop不会导致panic |
| 276 | func (c *Client) Stop() { |
no test coverage detected