flight

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package flight runs one call per key at a time and hands its result to every caller that asked while it ran, the way golang.org/x/sync/singleflight does, with each caller's context kept:

  • A call runs with the context of the caller that started it.
  • A caller stops waiting as soon as its own context ends; the call goes on for the others.
  • When a call ends because the context of the caller that started it ended, a caller still waiting does not take that as its answer: it starts the call again, under its own context.
  • A call that panics makes every caller waiting for it panic, each on its own goroutine, with a *PanicError, so whatever recovers a caller's panic recovers this one. The process is never brought down from a goroutine no caller owns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group[T any] struct {
	// contains filtered or unexported fields
}

Group runs calls that return a T, one per key at a time. The zero Group is ready to use, and a Group must not be copied after first use.

func (*Group[T]) Do

func (g *Group[T]) Do(ctx context.Context, key string, fn func(context.Context) (T, error)) (T, error)

Do runs fn under key with ctx, or waits for the call under key already running, and returns its result. It returns ctx's error as soon as ctx ends, whether or not the call has.

type PanicError

type PanicError struct {
	Value any
	Stack []byte
}

PanicError is what a caller panics with when the call it waited for panicked: the call's panic value and the stack where it happened.

func (*PanicError) Error

func (p *PanicError) Error() string

Error describes the panic with its stack.

func (*PanicError) Unwrap

func (p *PanicError) Unwrap() error

Unwrap returns the panic value when it is an error.

Jump to

Keyboard shortcuts

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