loop

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 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 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