adapters

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package adapters provides chi-style middleware around the runnable RunFunc signature. Each constructor returns a runnable.Adapter; compose them via runnable.WithAdapters (first listed = outermost):

r := runnable.New(reconcile, runnable.WithAdapters(
    adapters.Draining(10*time.Second),
    adapters.Ticker(time.Second),
))

Index

Constants

View Source
const ResetNever time.Duration = 0

ResetNever (as resetAfter) disables retry-budget reset.

Variables

View Source
var ErrDrainTimedOut = errors.New("adapters: drain timed out")

ErrDrainTimedOut is returned by Draining when work did not exit within the drain timeout and was force-cancelled.

Functions

func Draining

func Draining(timeout time.Duration) runnable.Adapter

Draining returns an Adapter that delays cancellation: when outerCtx is cancelled, next has up to timeout to return via Stopping(workCtx) before workCtx is force-cancelled and ErrDrainTimedOut is returned. Panics in next are recovered into an error (they would otherwise crash the process, since next runs on its own goroutine).

func Recovering

func Recovering() runnable.Adapter

Recovering returns an Adapter that converts panics from next into errors and publishes a runnable.PanicRecoveredEvent to the Publisher on ctx, if any. Place inside Draining when both are used, so the Publisher sees the panic before Draining's safety-net recovery formats it.

func Retry

func Retry(maxRetries int, resetAfter time.Duration) runnable.Adapter

Retry returns an Adapter that re-invokes next up to maxRetries times on non-context errors. If resetAfter > 0 and at least that long has passed since the previous attempt, the budget resets. Each failed attempt publishes a runnable.RetryEvent (Attempt is 1-indexed). Retry does not observe Stopping — wrap it inside Draining if you need both.

func Stopping

func Stopping(ctx context.Context) <-chan struct{}

Stopping returns a channel that closes when Draining begins shutdown, or nil outside Draining. Select on this alongside ctx.Done() — ctx is force-cancelled only after the drain timer expires.

func Ticker

func Ticker(interval time.Duration) runnable.Adapter

Ticker returns an Adapter that calls next once per interval until ctx is cancelled or next errors. Composes with Draining: an in-flight tick is allowed to finish before exit.

Types

This section is empty.

Jump to

Keyboard shortcuts

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