Documentation
¶
Overview ¶
Package mainthread pins the Go program's main goroutine to the process main thread and lets the rest of the program run on goroutines while the OS UI loop owns that thread. Cocoa requires this (NSApplication and all windows must live on the main thread); on Linux and Windows the shells run their own loops on private threads and Run merely provides the same program shape everywhere:
func main() {
mainthread.Run(func() { // app code runs on a goroutine
win, _ := auto.Open(cfg)
...
}) // returns when the func returns
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotRunning = errors.New("mainthread: Run is not active (call mainthread.Run from main)")
ErrNotRunning is returned by Do/Post when Run is not active.
Functions ¶
func Do ¶
func Do(f func()) error
Do runs f on the main thread and waits for it to finish. A panic in f is re-raised in the caller. Do must not be called from the main thread itself (i.e. from inside another Do/Post callback): it would deadlock.
func Run ¶
func Run(app func())
Run executes app on a new goroutine and runs the platform loop on the calling (main) thread until app returns. It must be called from main().
func SetPlatform ¶
func SetPlatform(p Platform)
SetPlatform replaces the default channel-based loop. Call from init().