uithread

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 4 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 uithread runs a task loop on a goroutine locked to its own OS thread: the UI thread of one window.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoroutineID

func GoroutineID() uint64

GoroutineID returns the calling goroutine's id, parsed from its stack header ("goroutine N [...]").

Types

type Thread

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

Thread is a goroutine locked to an OS thread and the FIFO of tasks it runs.

func Current

func Current() *Thread

Current returns the Thread the caller runs on, or nil if it is not on one.

func Start

func Start(name string) *Thread

Start starts a thread. When it returns the thread runs and its goroutine id is recorded. A panicking task crashes the process.

func StartWith

func StartWith(name string, onPanic func(any)) *Thread

StartWith is Start with a panic handler: a task that panics is recovered and onPanic is called with the value on the thread, which keeps running. A nil onPanic lets the panic propagate, as Start does.

func (*Thread) AwaitingMain

func (t *Thread) AwaitingMain() bool

AwaitingMain reports what SetAwaitingMain last recorded.

func (*Thread) Do

func (t *Thread) Do(fn func()) bool

Do runs fn on the thread and waits for it to return. Called on the thread itself it runs fn directly (even while draining after Stop). Otherwise it returns false, without running fn, if the thread is stopped.

func (*Thread) Done

func (t *Thread) Done() <-chan struct{}

Done is closed when the thread has exited.

func (*Thread) On

func (t *Thread) On() bool

On reports whether the caller is the thread.

func (*Thread) Post

func (t *Thread) Post(fn func()) bool

Post queues fn to run on the thread after the tasks queued before it. It may be called from any goroutine, the thread included (fn then runs after the current task returns). It returns false, dropping fn, if the thread is stopped.

func (*Thread) SetAwaitingMain

func (t *Thread) SetAwaitingMain(on bool)

SetAwaitingMain records whether the thread is blocked waiting for the main thread, so the main thread does not in turn wait for it.

func (*Thread) SetIdlePump

func (t *Thread) SetIdlePump(pump, wake func())

SetIdlePump installs (or clears) the UI thread's native event pump. Only the owned thread may call it. wake must latch a signal even if pump has not entered the native loop yet; it must not execute callbacks. On return from clearing it, no concurrent Post/Stop can call the old wake.

func (*Thread) Stop

func (t *Thread) Stop()

Stop makes the thread exit once it has run the tasks already queued; later Posts return false. It does not wait (see Done). Repeated calls have no effect.

func (*Thread) WatchAwaitingMain

func (t *Thread) WatchAwaitingMain() (awaiting bool, entered <-chan struct{})

WatchAwaitingMain atomically checks whether the thread is awaiting main and, if not, returns a channel closed the next time it starts to wait.

Jump to

Keyboard shortcuts

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