From 234800649783a2c9b593bcddbfad5648c9fa6b13 Mon Sep 17 00:00:00 2001 From: moznion Date: Mon, 8 Feb 2016 23:29:36 +0900 Subject: [PATCH] Add function for keep alive with arbitrary duration --- hipchat.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hipchat.go b/hipchat.go index b9795b7..9847ba0 100644 --- a/hipchat.go +++ b/hipchat.go @@ -120,7 +120,14 @@ func (c *Client) Say(roomId, name, body string) { // character to HipChat every 60 seconds. This keeps the connection from // idling after 150 seconds. func (c *Client) KeepAlive() { - for _ = range time.Tick(60 * time.Second) { + c.KeepAliveBy(60) +} + +// KeepAlive is meant to run as a goroutine. It sends a single whitespace +// character to HipChat every arbitrary seconds. This keeps the connection from +// idling after 150 seconds. +func (c *Client) KeepAliveBy(sec time.Duration) { + for _ = range time.Tick(sec * time.Second) { c.connection.KeepAlive() } }