internal/mainthread/mainthread.go
func Run(f func() error) error {
	if atomic.LoadInt32(&started) == 0 {
		// TODO: This can reach from other goroutine before Loop is called (#809).
		// panic("mainthread: the mainthread loop is not started yet")
	}

	ch := make(chan struct{})
	var err error
	funcs <- func() {
		err = f()
		close(ch)
	}
	<-ch
	return err
}
func Run(f func() error) error {
	if atomic.LoadInt32(&started) == 0 {
		// TODO: This can reach from other goroutine before Loop is called (#809).
		// panic("mainthread: the mainthread loop is not started yet")
	}

	ch := make(chan struct{})
	var err error
	funcs <- func() {
		err = f()
		close(ch)
	}
	<-ch
	return err
}
func Run ( f func ( ) error ) error { if atomic . LoadInt32 ( & started ) == 0 { // TODO: This can reach from other goroutine before Loop is called (#809). // panic("mainthread: the mainthread loop is not started yet") } ch := make ( chan struct { } ) var err error funcs <- func ( ) { err = f ( ) close ( ch ) } <- ch return err }
// Run calls f on the main thread.
//
// Do not call this from the main thread. This would block forever.
Run calls f on the main thread . Do not call this from the main thread . This would block forever .