feat: dispatcher and long poller options

This commit is contained in:
abelith committed 2026-10-05 14:15:20 +03:00
1 parent b5f1b426af
commit fd2ae3db72
3 files changed
+109 -23

No files matched your search

+19 -4
View File
@@ -12,7 +12,9 @@ import (
const defaultInterval = 200 * time.Millisecond
type PollerOption interface{}
type LongPollerOption interface {
apply(opts *longPollerOptions)
}
type Webhook struct{}
@@ -23,19 +25,26 @@ type LongPoller struct {
type TestPoller struct{}
type longPollerOptions struct {
pollInterval time.Duration
}
func (w *Webhook) Start(_ context.Context) (<-chan model.Update, error) {
return nil, fmt.Errorf("unimplemented")
}
func NewLongPoller(api *maxbot.Api, options ...PollerOption) *LongPoller {
func NewLongPoller(api *maxbot.Api, options ...LongPollerOption) *LongPoller {
lp := &LongPoller{
api: api,
}
if lp.pollInterval == 0 {
lp.pollInterval = defaultInterval
opts := newLongPollerOptions()
for _, opt := range options {
opt.apply(opts)
}
lp.pollInterval = opts.pollInterval
return lp
}
@@ -84,3 +93,9 @@ func (lp *LongPoller) Start(ctx context.Context) (<-chan model.Update, error) {
func (tp *TestPoller) Start(_ context.Context) (<-chan model.Update, error) {
return nil, fmt.Errorf("unimplemented")
}
func newLongPollerOptions() *longPollerOptions {
return &longPollerOptions{
pollInterval: defaultInterval,
}
}