loop

package
v1.17.14 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package loop has the plain-Go parts of the run loop that macOS and iOS share (SPEC §29.3, §30.2): the heap of timers that one CFRunLoopTimer is set to, the merging of the frame requests of a window, the pacer that starts and stops the display link, and the gate that offers one tick of a display link's thread at a time to the loop. Nothing here calls the operating system, so the tests run on every host.

Flutter: no counterpart

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FrameRequests

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

FrameRequests merges the requests of one window for a frame (SPEC §29.3): any number made while a frame is wanted are one frame, a request made during a frame asks for the next, and the request of a window that cannot draw (minimized, hidden) is kept until it can.

Flutter: shell/platform/darwin/macos/framework/Source/FlutterVSyncWaiter.mm (one request is answered by one tick of the display link)

func (*FrameRequests) Clear

func (f *FrameRequests) Clear()

Clear drops the request: a frame was drawn for another reason (a live resize draws at once).

Flutter: no counterpart

func (*FrameRequests) Request

func (f *FrameRequests) Request()

Request records a request for a frame.

Flutter: no counterpart

func (*FrameRequests) Take

func (f *FrameRequests) Take(canDraw bool) bool

Take says whether the window draws in this tick: a frame is wanted and the window can draw it. The Request is consumed before the frame is drawn, so that a request made during the frame asks for the one after it.

Flutter: no counterpart

func (*FrameRequests) Wanted

func (f *FrameRequests) Wanted() bool

Wanted says whether a frame is wanted now.

Flutter: no counterpart

type LinkPacer

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

LinkPacer decides when the display link runs (SPEC §29.3): it runs only while some window wants a frame and can draw it, so an idle app has no link ticking. It belongs to the UI thread.

Flutter: no counterpart (FlutterDisplayLink is paused by the vsync waiter when nothing waits)

func (*LinkPacer) Running

func (p *LinkPacer) Running() bool

Running says whether the link is running now: Update last said to start it and has not said to stop it.

Flutter: no counterpart

func (*LinkPacer) Update

func (p *LinkPacer) Update(anyWanted bool) (start, stop bool)

Update is told after every change whether some window wants a frame it can draw, and says whether the link must be started (true, false) or stopped (false, true). With neither it is already as wanted.

Flutter: no counterpart

type LinkWatch

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

LinkWatch decides which of two display links paces the frames (SPEC §29.3): the preferred one (the view's CADisplayLink, which follows the display and its refresh rate) and a fallback that always ticks (a CVDisplayLink). The preferred link stays silent for a window on a display that sleeps, which is also what a Mac shows when it is used through Screen Sharing with its own screen asleep: the window is looked at and must be drawn. So the preferred link is watched while it runs: when a watch interval passes with no tick of it the fallback takes over, a tick of the preferred link takes the pacing back, and while the preferred link is silent every start goes to the fallback at once. It belongs to the UI thread.

Flutter: no counterpart (FlutterDisplayLink is a CVDisplayLink on every version of macOS)

func (*LinkWatch) Check

func (w *LinkWatch) Check() (startFallback bool)

Check is called when a watch interval has passed. It says whether the fallback must be started: the links run, the preferred one paces and it did not tick in the interval. The next interval starts.

Flutter: no counterpart

func (*LinkWatch) Fallback

func (w *LinkWatch) Fallback() bool

Fallback says whether the fallback paces the frames: a tick of it is a frame only then.

Flutter: no counterpart

func (*LinkWatch) Start

func (w *LinkWatch) Start() (startFallback bool)

Start is told that the links are wanted. It says whether the fallback must be started as well (the preferred link was silent the last time it was watched); the preferred link is always started, so that its first tick is seen.

Flutter: no counterpart

func (*LinkWatch) Stop

func (w *LinkWatch) Stop()

Stop is told that no link is wanted any more. The fallback, when it ran, is stopped by the caller; that the preferred link was silent is remembered for the next Start.

Flutter: no counterpart

func (*LinkWatch) Tick

func (w *LinkWatch) Tick() (stopFallback bool)

Tick is told of a tick of the preferred link. It says whether the fallback must be stopped: the preferred link paces the frames again.

Flutter: no counterpart

func (*LinkWatch) Watching

func (w *LinkWatch) Watching() bool

Watching says whether a watch interval must be timed: the links run and the preferred one paces.

Flutter: no counterpart

type TickGate

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

TickGate lets one tick of a display link thread (CVDisplayLink calls back on a thread of its own) be offered to the loop at a time: a tick that arrives while the previous one is still waiting is dropped, as Flutter's FlutterDisplayLink does, so a slow loop never collects a queue of ticks. It is safe to use from the link's thread and from the UI thread.

Flutter: shell/platform/darwin/macos/framework/Source/FlutterDisplayLink.mm (the tick is dropped while the main thread has not handled the last)

func (*TickGate) Done

func (g *TickGate) Done()

Done records that the loop handled the tick, so that the next one is let through.

Flutter: no counterpart

func (*TickGate) Offer

func (g *TickGate) Offer() bool

Offer says whether the tick must be posted to the loop: false when one is already on its way.

Flutter: no counterpart

type TimerID

type TimerID uint64

TimerID names a timer of a Timers, to cancel it.

type Timers

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

Timers is the platform's own heap of timers (SPEC §29.3): one CFRunLoopTimer is set to the earliest deadline (SetNextFire) and the heap runs what is due when it fires. It belongs to the UI thread, so it needs no lock.

Flutter: shell/platform/darwin/macos/framework/Source/FlutterRunLoop.swift FlutterRunLoop (its scheduled blocks run in the main run loop)

func (*Timers) Add

func (h *Timers) Add(at time.Time, fn func()) TimerID

Add arms fn to run at the time and returns the id to cancel it with.

Flutter: no counterpart

func (*Timers) Cancel

func (h *Timers) Cancel(id TimerID) bool

Cancel disarms a timer and reports whether it was still armed.

Flutter: no counterpart

func (*Timers) Deadline

func (h *Timers) Deadline() (at time.Time, ok bool)

Deadline is when the earliest timer is due; ok is false when none is armed, which makes the loop wait for ever.

Flutter: no counterpart

func (*Timers) RunDue

func (h *Timers) RunDue(now time.Time) int

RunDue runs the timers that are due at now, the earliest first and those of one instant in the order they were armed, and returns how many ran. A function may arm and cancel timers; one it arms for a time that is already due also runs.

Flutter: no counterpart

func (*Timers) WaitFor

func (h *Timers) WaitFor(now time.Time) (d time.Duration, ok bool)

WaitFor is how long the loop may wait from now: the time to the earliest timer (0 when it is due), and false when none is armed.

Flutter: no counterpart

Jump to

Keyboard shortcuts

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