all repos — telegram-bot-api @ 444e8e261f9fb6b8b0f13a1436d32db6233df66a

Golang bindings for the Telegram Bot API

Merge pull request #154 from Arman92/patch-1

added StopReceivingUpdates to stop updates routine
Syfaro syfaro@huefox.com
Mon, 08 Oct 2018 02:08:42 -0500
commit

444e8e261f9fb6b8b0f13a1436d32db6233df66a

parent

5f38203a155afa901c7deb70596a088a8424a9ee

1 files changed, 16 insertions(+), 0 deletions(-)

jump to
M bot.gobot.go

@@ -27,6 +27,7 @@ Buffer int `json:"buffer"`

Self User `json:"-"` Client *http.Client `json:"-"` + shutdownChannel chan interface{} } // NewBotAPI creates a new BotAPI instance.

@@ -45,6 +46,7 @@ bot := &BotAPI{

Token: token, Client: client, Buffer: 100, + shutdownChannel: make(chan interface{}), } self, err := bot.GetMe()

@@ -483,6 +485,12 @@ ch := make(chan Update, bot.Buffer)

go func() { for { + select { + case <-bot.shutdownChannel: + return + default: + } + updates, err := bot.GetUpdates(config) if err != nil { log.Println(err)

@@ -499,6 +507,14 @@ }

}() return ch, nil +} + +// StopReceivingUpdates stops the go routine which receives updates +func (bot *BotAPI) StopReceivingUpdates() { + if bot.Debug { + log.Println("Stopping the update receiver routine...") + } + close(bot.shutdownChannel) } // ListenForWebhook registers a http handler for a webhook.