Add Interval to UpdateConfig, and method for set it

pull/281/head
youaresofunny 6 years ago
parent e9a86f840c
commit ae54c74c29
  1. 7
      bot.go
  2. 8
      configs.go
  3. 2
      helpers.go

@ -9,6 +9,7 @@ import (
"fmt"
"io"
"io/ioutil"
_ "log"
"net/http"
"net/url"
"os"
@ -492,13 +493,12 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) {
ch := make(chan Update, bot.Buffer)
go func() {
ticker := time.NewTicker(config.Interval)
for {
select {
case <-bot.shutdownChannel:
return
default:
}
case <-ticker.C:
updates, err := bot.GetUpdates(config)
if err != nil {
log.Println(err)
@ -515,6 +515,7 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) {
}
}
}
}
}()
return ch, nil

@ -5,6 +5,7 @@ import (
"io"
"net/url"
"strconv"
"time"
)
// Telegram constants
@ -955,6 +956,13 @@ type UpdateConfig struct {
Offset int
Limit int
Timeout int
Interval time.Duration
}
const UpdateDefaultInterval = time.Second
func (uc *UpdateConfig) SetInterval(t time.Duration) {
uc.Interval = t
}
// WebhookConfig contains information about a SetWebhook request.

@ -1,6 +1,7 @@
package got
import (
_ "log"
"net/url"
)
@ -385,6 +386,7 @@ func NewUpdate(offset int) UpdateConfig {
Offset: offset,
Limit: 0,
Timeout: 0,
Interval: UpdateDefaultInterval,
}
}