floodwait

package
Version: v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package floodwait implements a tg.Invoker that handles flood wait errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SimpleWaiter

type SimpleWaiter struct {
	// contains filtered or unexported fields
}

SimpleWaiter is a tg.Invoker that handles flood wait errors on underlying invoker.

This implementation is more suitable for one-off tasks and programs with low level of concurrency and parallelism.

See Waiter for a fully-blown scheduler-based flood wait handler.

func NewSimpleWaiter

func NewSimpleWaiter() *SimpleWaiter

NewSimpleWaiter returns a new invoker that waits on the flood wait errors.

func (*SimpleWaiter) Handle

func (w *SimpleWaiter) Handle(next tg.Invoker) telegram.InvokeFunc

Handle implements telegram.Middleware.

func (*SimpleWaiter) WithClock

func (w *SimpleWaiter) WithClock(c clock.Clock) *SimpleWaiter

WithClock sets clock to use. Default is to use system clock.

func (*SimpleWaiter) WithMaxRetries

func (w *SimpleWaiter) WithMaxRetries(m uint) *SimpleWaiter

WithMaxRetries sets max number of retries before giving up. Default is to keep retrying on flood wait errors indefinitely.

func (*SimpleWaiter) WithMaxWait

func (w *SimpleWaiter) WithMaxWait(m time.Duration) *SimpleWaiter

WithMaxWait limits wait time per attempt. SimpleWaiter will return an error if flood wait time exceeds that limit. Default is to wait without time limit.

To limit total wait time use a context.Context with timeout or deadline set.

type Waiter

type Waiter struct {
	// contains filtered or unexported fields
}

Waiter is a tg.Invoker that handles flood wait errors on underlying invoker.

This implementation uses a request scheduler and is more suitable for long-running programs with high level of concurrency and parallelism.

You should use Waiter if unsure which waiter implementation to use.

See SimpleWaiter for a simple timer-based implementation.

func NewWaiter

func NewWaiter() *Waiter

NewWaiter returns a new invoker that waits on the flood wait errors.

func (*Waiter) Handle

func (w *Waiter) Handle(next tg.Invoker) telegram.InvokeFunc

Handle implements telegram.Middleware.

func (*Waiter) Run

func (w *Waiter) Run(ctx context.Context) error

Run runs send loop.

func (*Waiter) WithClock

func (w *Waiter) WithClock(c clock.Clock) *Waiter

WithClock sets clock to use. Default is to use system clock.

func (*Waiter) WithMaxRetries

func (w *Waiter) WithMaxRetries(m int) *Waiter

WithMaxRetries sets max number of retries before giving up. Default is to retry at most 5 times.

func (*Waiter) WithMaxWait

func (w *Waiter) WithMaxWait(m time.Duration) *Waiter

WithMaxWait limits wait time per attempt. Waiter will return an error if flood wait time exceeds that limit. Default is to wait at most a minute.

To limit total wait time use a context.Context with timeout or deadline set.

func (*Waiter) WithTick

func (w *Waiter) WithTick(t time.Duration) *Waiter

WithTick sets gather tick interval for Waiter. Default is 1ms.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to