local

package
v0.10.0-alpha.33 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package local executes non-serializable process-local closures as managed tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Manager   *backgroundtask.Manager
	Executors *backgroundtask.ExecutorRegistry
	// ForegroundTimeoutMs is the default foreground observation timeout for runs
	// that do not set Input.ForegroundTimeoutMs. Nil uses the framework default
	// (backgroundtask.DefaultForegroundTimeoutMs); a non-positive value disables
	// the timer, so runs wait until the work returns or ctx is canceled and
	// ShouldAutoBackground is never consulted.
	ForegroundTimeoutMs  *int
	ShouldAutoBackground func(context.Context, *backgroundtask.ForegroundCandidate) bool
	BackgroundNotice     func(context.Context, NoticeInfo) string
}

Config configures process-local execution and ephemeral foreground projection. Policy callbacks may run concurrently and must not panic or mutate the supplied candidate. Nil ShouldAutoBackground disables automatic detachment; nil BackgroundNotice uses the default notice.

type Input

type Input struct {
	Description                string
	Kind                       string
	Payload                    []byte
	OutputFile                 string
	SessionID                  string
	NotifySession              bool
	RunInBackground            bool
	BackgroundStartupPreviewMs int
	// ForegroundTimeoutMs bounds how long this run is observed in the foreground.
	// Nil falls back to Config.ForegroundTimeoutMs. A non-positive value disables
	// the timer: the caller waits until the work returns or ctx is canceled, and
	// Config.ShouldAutoBackground is never consulted, since it is only evaluated on
	// timer expiry. Ignored when RunInBackground is set.
	ForegroundTimeoutMs *int
}

Input describes one process-local execution. ForegroundTimeoutMs overrides Config.ForegroundTimeoutMs. RunInBackground bypasses foreground timeout; BackgroundStartupPreviewMs applies only to its streaming startup preview.

type NoticeInfo

type NoticeInfo struct {
	Task             *backgroundtask.Task
	AutoBackgrounded bool
}

NoticeInfo carries lifecycle facts for a background stream notice. Task may be nil when authoritative loading fails.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner owns one process-local closure registry for a Manager.

func New

func New(config *Config) (*Runner, error)

New constructs a Runner and registers its process-local executor.

func (*Runner) Manager

func (r *Runner) Manager() *backgroundtask.Manager

Manager returns the shared lifecycle Manager.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, input *Input, work WorkFunc) (*backgroundtask.Task, error)

Run executes buffered process-local work. If the configured foreground timeout expires without a successful background handoff, Run returns a *backgroundtask.ForegroundTimeoutError.

func (*Runner) RunStream

func (r *Runner) RunStream(
	ctx context.Context,
	input *Input,
	work StreamWorkFunc,
) (*schema.StreamReader[string], error)

RunStream executes streaming process-local work and returns its ephemeral caller-facing projection. Foreground chunks are not task events because no durable task exists until explicit background launch or successful handoff. Closing a foreground reader requests cancellation of this process-local operation; closing a background preview only closes the caller projection. A foreground timeout is sent through the reader as a *backgroundtask.ForegroundTimeoutError.

type StreamWorkFunc

type StreamWorkFunc func(
	ctx context.Context,
	runtime backgroundtask.ExecutionRuntime,
) (*schema.StreamReader[string], error)

StreamWorkFunc performs streaming process-local work.

type WorkFunc

type WorkFunc func(
	ctx context.Context,
	runtime backgroundtask.ExecutionRuntime,
) (string, error)

WorkFunc performs buffered process-local work.

Jump to

Keyboard shortcuts

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