Change visibility of UpdatesChannel, closes #76
Syfaro syfaro@foxpaw.in
Thu, 26 Jan 2017 11:43:28 -0600
3 files changed,
8 insertions(+),
9 deletions(-)
M
bot.go
→
bot.go
@@ -456,7 +456,7 @@ return info, err
} // GetUpdatesChan starts and returns a channel for getting updates. -func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (updatesChannel, error) { +func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) { ch := make(chan Update, 100) go func() {@@ -483,7 +483,7 @@ return ch, nil
} // ListenForWebhook registers a http handler for a webhook. -func (bot *BotAPI) ListenForWebhook(pattern string) updatesChannel { +func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel { ch := make(chan Update, 100) http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
M
bot_test.go
→
bot_test.go
@@ -485,10 +485,9 @@ u.Timeout = 60
updates, err := bot.GetUpdatesChan(u) - //If you need to clear all the updates when bot just started: - //Wait to gather all the new updates (choose the time conveniently) + // Optional: wait for updates and clear them if you don't want to handle + // a large backlog of old messages time.Sleep(time.Millisecond * 500) - //discard all the updates preventing the spam after your server has been down updates.Clear() for update := range updates {
M
types.go
→
types.go
@@ -37,11 +37,11 @@ ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
CallbackQuery *CallbackQuery `json:"callback_query"` } -//updatesChannel is the channel for getting updates. -type updatesChannel <-chan Update +// UpdatesChannel is the channel for getting updates. +type UpdatesChannel <-chan Update -//Clear discards all the actual incoming updates -func (ch updatesChannel) Clear() { +// Clear discards all unprocessed incoming updates. +func (ch UpdatesChannel) Clear() { for len(ch) != 0 { <-ch }