pull

package
v0.2024.5 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package pull provides a reliable way to subscribe to changes from a device.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Changes

func Changes[C any](ctx context.Context, poller Fetcher[C], changes chan<- C, opts ...Option) error

Changes calls Pull on poller unless it's not supported, in which case it polls. It will retry on error, backing off exponentially up to a maximum delay. It will return if the context is cancelled or a non-recoverable error occurs.

func OrPoll

func OrPoll(ctx context.Context, pull, poll Getter, opts ...Option) error

OrPoll will attempt to call pull, falling back to poll if it's not supported. pull subscribe to changes, blocking until the subscription fails, if possible failures will be retried. poll should query for the current state, this function manages delays between calls.

Types

type Fetcher

type Fetcher[C any] interface {
	// Pull blocks subscribing to changes and sends them on the given channel.
	// Retries and reconnects are managed by the caller.
	Pull(ctx context.Context, changes chan<- C) error
	// Poll queries for the current value sending it on the given channel.
	// Delays between polls are managed by the caller.
	Poll(ctx context.Context, changes chan<- C) error
}

Fetcher can pull and poll for changes.

func NewFetcher

func NewFetcher[C any](pull, poll func(ctx context.Context, changes chan<- C) error) Fetcher[C]

NewFetcher returns a Fetcher backed by the given pull and poll functions.

type Getter

type Getter = func(context.Context) error

type Option

type Option func(opts *changeOpts)

func WithLogger

func WithLogger(logger *zap.Logger) Option

func WithPollDelay

func WithPollDelay(delay time.Duration) Option

func WithPullFallback

func WithPullFallback(initial, max time.Duration) Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳