invokers

package
v0.39.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package invokers contains some middlewares and helpers to work with RPC invokers.

Index

Examples

Constants

View Source
const ErrFloodWait = "FLOOD_WAIT"

ErrFloodWait is error type of "FLOOD_WAIT" error.

Variables

This section is empty.

Functions

This section is empty.

Types

type Object

type Object interface {
	TypeID() uint32
}

Object is a abstraction for Telegram API object with TypeID.

type RateLimiter added in v0.39.0

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

RateLimiter is a tg.Invoker that throttles RPC calls on underlying invoker.

Example
package main

import (
	"time"

	"golang.org/x/time/rate"

	"github.com/gotd/td/telegram/invokers"
	"github.com/gotd/td/tg"
)

func main() {
	var invoker tg.Invoker // e.g. *telegram.Client

	limiter := invokers.NewRateLimiter(invoker,
		rate.NewLimiter(rate.Every(100*time.Millisecond), 1),
	)

	tg.NewClient(limiter)
}
Output:

func NewRateLimiter added in v0.39.0

func NewRateLimiter(invoker tg.Invoker, lim *rate.Limiter) *RateLimiter

NewRateLimiter returns a new invoker rate limiter using lim.

func (*RateLimiter) InvokeRaw added in v0.39.0

func (l *RateLimiter) InvokeRaw(ctx context.Context, input bin.Encoder, output bin.Decoder) error

InvokeRaw implements tg.Invoker.

func (*RateLimiter) WithClock added in v0.39.0

func (l *RateLimiter) WithClock(c clock.Clock) *RateLimiter

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

type Waiter

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

Waiter is a invoker middleware to handle FLOOD_WAIT errors from Telegram.

func NewWaiter

func NewWaiter(prev tg.Invoker) *Waiter

NewWaiter creates new Waiter invoker middleware.

func (*Waiter) InvokeRaw

func (w *Waiter) InvokeRaw(ctx context.Context, input bin.Encoder, output bin.Decoder) error

InvokeRaw implements tg.Invoker.

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.

func (*Waiter) WithRetryLimit

func (w *Waiter) WithRetryLimit(retryLimit int) *Waiter

WithRetryLimit sets retry limit to use.

func (*Waiter) WithTick

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

WithTick sets gather tick for Waiter.

func (*Waiter) WithWaitLimit

func (w *Waiter) WithWaitLimit(waitLimit int) *Waiter

WithWaitLimit sets wait limit to use.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL