scheduler

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package scheduler provides page-scoped timing APIs exposed to WebGo programs.

Index

Constants

View Source
const (
	Millisecond = time.Millisecond
	Second      = time.Second
	// MaxTimerDuration bounds retained callbacks and deadline arithmetic.
	MaxTimerDuration = 365 * 24 * time.Hour
	// MaxTimersPerPage bounds callbacks retained by timeouts and intervals.
	MaxTimersPerPage = 10000
	// MaxFrameCallbacksPerPage bounds callbacks retained until the next frame.
	MaxFrameCallbacksPerPage = 10000
	// MaxCallbacksPerTurn prevents one deadline from starving the Page queue.
	MaxCallbacksPerTurn = 1000
)

WebGo programs can build time.Duration values without importing the Go standard library, which is intentionally not part of the page API surface.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API owns the active timers for one page.

func NewPage

func NewPage(parent context.Context, enqueue func(func()) bool, requestFrame func()) *API

NewPage creates a scheduler that waits for deadlines and delivers callbacks through enqueue.

func NewPageWithClock

func NewPageWithClock(parent context.Context, clock Clock, enqueue func(func()) bool, requestFrame func()) *API

NewPageWithClock creates a manually driven page Scheduler. Embedders and tests advance timers through RunDue, so no wall-clock goroutine is started.

func (*API) CancelAnimationFrame

func (api *API) CancelAnimationFrame(id FrameID) bool

CancelAnimationFrame removes a callback that has not started.

func (*API) ClearTimer

func (api *API) ClearTimer(id TimerID) bool

ClearTimer cancels a timeout or interval before its next callback starts.

func (*API) Close

func (api *API) Close()

Close cancels every timer and releases page callback references.

func (*API) HasAnimationFrameCallbacks

func (api *API) HasAnimationFrameCallbacks() bool

HasAnimationFrameCallbacks reports whether another rendered frame is needed.

func (*API) RequestAnimationFrame

func (api *API) RequestAnimationFrame(callback func(Timestamp)) (FrameID, error)

RequestAnimationFrame registers callback for the next rendered frame.

func (*API) RunAnimationFrame

func (api *API) RunAnimationFrame(current time.Time) bool

RunAnimationFrame delivers the callbacks captured for one frame. Callers must invoke it from the page event queue.

func (*API) RunDue

func (api *API) RunDue(current time.Time)

RunDue synchronously queues all timers whose deadline is at or before current. It is intended for a manually driven Scheduler.

func (*API) SetFrameScope

func (api *API) SetFrameScope(scope func(time.Time, func()))

SetFrameScope configures the page-owned scope used while frame callbacks run.

func (*API) SetInterval

func (api *API) SetInterval(interval time.Duration, callback func()) (TimerID, error)

SetInterval registers callback to run repeatedly after each interval.

func (*API) SetTimeout

func (api *API) SetTimeout(delay time.Duration, callback func()) (TimerID, error)

SetTimeout registers callback to run once after delay.

type Clock

type Clock interface {
	Now() time.Time
}

Clock supplies monotonic time to the scheduler.

type FrameID

type FrameID uint64

FrameID identifies one animation frame callback within a page.

type TimerID

type TimerID uint64

TimerID identifies one timeout or interval within a page.

type Timestamp

type Timestamp time.Duration

Timestamp is elapsed monotonic time on the page animation timeline.

Jump to

Keyboard shortcuts

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