(new): updates iterator
Golang lint / lint (push) Successful in 2m15s

(new): sneklog migration

(refactor): idiomatic names

(fix): polling lifecycle

(tests): polling regressions

(doc): rc16 changelog
This commit is contained in:
2026-04-29 12:31:41 +03:00
parent fc4386df75
commit 667fa3cc61
5 changed files with 174 additions and 8 deletions
+20
View File
@@ -3,6 +3,7 @@ package laniakea
import (
"context"
"encoding/json"
"iter"
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
)
@@ -67,3 +68,22 @@ func (bot *Bot[T]) Updates(ctx context.Context) ([]tgapi.Update, error) {
}
return updates, err
}
// UpdatesIter fetches updates once and yields each update in order.
//
// If fetching updates fails, the iterator yields the error once with a zero
// update and then stops.
func (bot *Bot[T]) UpdatesIter(ctx context.Context) iter.Seq2[tgapi.Update, error] {
return func(yield func(tgapi.Update, error) bool) {
updates, err := bot.Updates(ctx)
if err != nil {
yield(tgapi.Update{}, err)
return
}
for _, u := range updates {
if !yield(u, nil) {
return
}
}
}
}