ctxrl

package
v0.0.0-...-9648343 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package ctxrl implements context-based rate limiting. It is intended to be used on TMI for rate limiting messages to channels in slow mode. It implements a message queue in order to integrate with a blocking rate limiter that ensures a global maximum rate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextMessage

type ContextMessage struct {
	Context   string // Usually a channel
	Publisher Publisher
}

A ContextMessage describes a message to-be-enqueued.

type Limiter

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

A Limiter rate-limits messages to a context, such as a Twitch channel.

func New

func New() *Limiter

New creates a new Limiter.

func (*Limiter) Output

func (b *Limiter) Output(ctx context.Context)

Output should be used as a background routine that writes message according to the rate limit of each context.

func (*Limiter) Pending

func (b *Limiter) Pending(ctx string) int

Pending returns the number of outstanding (to be sent) messages for the given context.

func (*Limiter) Send

func (b *Limiter) Send(msg ContextMessage, ival time.Duration) int

Send schedules a message to be sent in a context. It is up to the caller to limit the total number of messages that can be queued.

A negative `ival` means it is not known, in which case the previous interval will be assumed to be correct.

type Publisher

type Publisher interface {
	Publish()
}

A Publisher pushes the output to the desired connection behind the scenes. The call should block until it is reasonably certain the message will be sent as soon as possible, to avoid conflicting with the rate limiting.

Jump to

Keyboard shortcuts

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