preempt

package
v0.17.0 Latest Latest
Warning

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

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

Documentation

Overview

Package preempt implements cooperative scheduling for preemptable functions that can await keys produced by other functions.

Index

Constants

View Source
const ErrUnresolvable errors.Kind = "unresolvable key"

ErrUnresolvable is an error that indicates that Await could not complete.

Variables

This section is empty.

Functions

func Await

func Await(ctx context.Context, key string) error

Await blocks until the given key has been produced by another Preemptable function. It returns immediately if the key was already completed. This function must only be called from within Run, using the given context.

func Run

func Run(ctx context.Context, fns iter.Seq[Preemptable]) error

Run executes the given functions cooperatively, one at a time. Functions may call Await to yield until a key produced by another function becomes available.

Types

type Preemptable

type Preemptable func(ctx context.Context) (keys []string, err error)

Preemptable is a function that can be scheduled by Run. It returns one or more keys that other functions may be awaiting via Await.

Jump to

Keyboard shortcuts

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