bot: fix long poller stopping logic

pull/275/head
Demian 4 years ago
parent 0910baadba
commit c14c51a668

@ -174,18 +174,19 @@ func (b *Bot) Start() {
// handle incoming updates
case upd := <-b.Updates:
b.incomingUpdate(&upd)
// call to stop polling
case <-b.stop:
stop <- struct{}{}
// polling has stopped
case <-stop:
return
}
}
}
// Stop gracefully shuts the poller down.
func (b *Bot) Stop() {
b.stop <- struct{}{}
}
func (b *Bot) incomingUpdate(upd *Update) {
if upd.Message != nil {
m := upd.Message
@ -505,11 +506,6 @@ func (b *Bot) handleMedia(m *Message) bool {
return true
}
// Stop gracefully shuts the poller down.
func (b *Bot) Stop() {
b.stop <- struct{}{}
}
// Send accepts 2+ arguments, starting with destination chat, followed by
// some Sendable (or string!) and optional send options.
//

@ -98,12 +98,14 @@ type LongPoller struct {
// Poll does long polling.
func (p *LongPoller) Poll(b *Bot, dest chan Update, stop chan struct{}) {
go func(stop chan struct{}) {
<-stop
close(stop)
}(stop)
for {
select {
case <-stop:
close(stop)
return
default:
}
updates, err := b.getUpdates(p.LastUpdateID+1, p.Limit, p.Timeout, p.AllowedUpdates)
if err != nil {
b.debug(err)

Loading…
Cancel
Save