Documentation
¶
Overview ¶
Package uithread runs a task loop on a goroutine locked to its own OS thread: the UI thread of one window.
Index ¶
- func GoroutineID() uint64
- type Thread
- func (t *Thread) AwaitingMain() bool
- func (t *Thread) Do(fn func()) bool
- func (t *Thread) Done() <-chan struct{}
- func (t *Thread) On() bool
- func (t *Thread) Post(fn func()) bool
- func (t *Thread) SetAwaitingMain(on bool)
- func (t *Thread) SetIdlePump(pump, wake func())
- func (t *Thread) Stop()
- func (t *Thread) WatchAwaitingMain() (awaiting bool, entered <-chan struct{})
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 ¶
Start starts a thread. When it returns the thread runs and its goroutine id is recorded. A panicking task crashes the process.
func StartWith ¶
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 ¶
AwaitingMain reports what SetAwaitingMain last recorded.
func (*Thread) Do ¶
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) Post ¶
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 ¶
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 ¶
WatchAwaitingMain atomically checks whether the thread is awaiting main and, if not, returns a channel closed the next time it starts to wait.