sf

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package sf provides a tiny generic singleflight-style coalescer used internally by middlewares that need to dedupe concurrent in-flight producers for the same key (middleware/cache — and, potentially, future adapters). The public middleware/singleflight package serves a different purpose (HTTP-response coalescing at the chain level) and owns its own implementation tuned for http/celeris types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call[T any] struct {
	Result T
	Err    error
	// contains filtered or unexported fields
}

Call is a single in-flight call for a key. Followers block on wg; the leader populates Result/Err before calling wg.Done.

type Group

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

Group coalesces concurrent calls keyed by string. The leader runs the producer; followers block on the leader's result.

func New

func New[T any]() *Group[T]

New returns an initialised Group[T].

func (*Group[T]) Do

func (g *Group[T]) Do(key string, fn func() (T, error)) (T, bool, error)

Do runs fn for the first caller of a given key and returns its result to every caller. The bool second return is true for the leader (the caller that actually ran fn) and false for followers.

Jump to

Keyboard shortcuts

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