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

scriptpace

package
v1.150.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package scriptpace is a managed script's clock: platform.remaining_ms, the time the run has before its deadline (#2004), and platform.sleep, a bounded wait that lets a script poll a slow upstream with short calls instead of one call held open until the upstream answers (#2112).

A wait is held to the run: one call waits at most MaxSeconds, so a loop of waits stays visible in the run's step and time budgets, and a wait that would carry the run past its deadline is refused before it starts. A test and a replay do not wait at all -- the call returns at once and records nothing -- so a polling script's tests stay fast and replay the same calls in the same order a run made them. remaining_ms is recorded with the run and read back from the recording, or from testing.set_run, in a test.

It is kept out of internal/platform/scriptrun for that package's size budget: scriptrun binds the two members over a Clock and owns nothing else of them.

Index

Constants

View Source
const MaxSeconds = 60

MaxSeconds is the longest one call waits. A longer wait is a loop of shorter ones, which is what keeps it visible.

View Source
const SleepCapability = "platform.sleep"

SleepCapability is platform.sleep's name as the run reports and validate spells it.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock struct {
	// Ctx is the run's context, whose deadline is the run's.
	Ctx context.Context //nolint:containedctx // the run's lifetime, which both members read
	// Testing is a test or a replay: remaining_ms reads a value back and
	// sleep returns at once.
	Testing bool
	// Pinned reads the value testing.set_run(remaining_ms=...) set, nil when
	// a test set none. It is read at each call, because a test sets it after
	// the run's environment is built.
	Pinned func() *int64
	// Recorded reads a value a recorded run read from the host, nil when
	// there is no recording.
	Recorded func(name string) (map[string]any, error)
	// Record records a value the run read, nil when nothing records.
	Record func(tool string, args, out map[string]any, err error)
}

Clock is a run's time as its script reads it.

func (Clock) RemainingMS

func (c Clock) RemainingMS(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

RemainingMS reports the milliseconds the run has before its deadline. A script has no clock, so a long job that budgets its time would otherwise add up duration_ms from its answers, which misses everything that is not a tool answer.

func (Clock) Sleep

func (c Clock) Sleep(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Sleep waits the seconds a call asks for, within the run's deadline.

Jump to

Keyboard shortcuts

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