Help us shape the future of Go! Take the 2026 Go Developer Survey

flight

package
v0.2.34 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package flight collapses concurrent calls for the same key into one execution whose result every caller shares.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Group runs at most one call per key at a time. The zero Group is ready.

func (*Group[K, V]) Do

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

Do shares fn among concurrent callers of key. The first caller runs fn on its own goroutine and context, so no work outlives a caller that owns it. Others wait; if the leader's context ended the call, a waiter whose own context is live runs fn itself instead of inheriting that cancellation. Callers share the returned value and must not mutate it.

func (*Group[K, V]) DoDetached

func (g *Group[K, V]) DoDetached(ctx context.Context, key K, fn func(context.Context) (V, error)) (V, error)

DoDetached shares fn among concurrent callers of key. fn runs to completion on its own goroutine with a context that keeps the first caller's values but none of its cancellation, so one caller giving up never fails the others; fn must bound its own work. Every caller, including the first, returns ctx.Err() as soon as its context ends. Callers share the returned value and must not mutate it.

func (*Group[K, V]) Has

func (g *Group[K, V]) Has(key K) bool

Has reports whether key has a call in flight.

func (*Group[K, V]) Len

func (g *Group[K, V]) Len() int

Len reports how many keys have a call in flight.

Jump to

Keyboard shortcuts

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