longpoll

package
v0.4.22 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = Config{
	RetryTime:   time.Millisecond * 500,
	MinWaitTime: time.Second,
	MaxWaitTime: time.Second * 60,
}

Default configuration for http long polling wait half a second between retries, min 1 sec and max 60 sec

Functions

func Until

func Until(ctx context.Context, d time.Duration, fn LongPollFunc) (ok bool, err error)

Until executes the given function fn until duration d is passed or context is canceled. The constaints of the Default configuration apply.

Types

type Config

type Config struct {
	// RetryTime time to wait between two retries
	RetryTime time.Duration
	// MinWaitTime min time to wait
	MinWaitTime time.Duration
	// MaxWaitTime max time to wait
	MaxWaitTime time.Duration
}

Config for long polling

func (Config) LongPollUntil

func (c Config) LongPollUntil(ctx context.Context, d time.Duration, fn LongPollFunc) (ok bool, err error)

LongPollUntil executes the given function fn until duration d is passed or context is canceled. If duration is below or above the MinWaitTime, MaxWaitTime from the Config, the values will be set to the allowed min/max respectively. Other checking is up to the caller. The resulting time budget is communicated via the provided context. This is a defence measure to not have accidental long running routines. If no duration is given (0) the long poll will have exactly one execution.

type LongPollFunc

type LongPollFunc func(context.Context) (bool, error)

LongPollFunc should return true if long polling did resolve, false otherwise. If error is returned, the long polling will be canceled. The passed context will be guarded by the time budget (deadline) of the longpolling request.

Jump to

Keyboard shortcuts

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