MCPcopy Index your code
hub / github.com/aceld/zinx / StartHeartBeatWithOption

Method StartHeartBeatWithOption

znet/client.go:257–273  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

255// option: a HeartBeatOption struct that contains the custom callback function and message
256// 启动心跳检测(自定义回调)
257func (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
276func (c *Client) Stop() {

Callers 1

mainFunction · 0.95

Calls 7

SetHeartbeatMsgFuncMethod · 0.95
SetOnRemoteNotAliveMethod · 0.95
BindRouterMethod · 0.95
AddRouterMethod · 0.95
MsgIDMethod · 0.95
RouterMethod · 0.95
NewHeartbeatCheckerFunction · 0.85

Tested by

no test coverage detected