func CallErr(f func() error) error {
	checkRun()
	errChan := make(chan error)
	callQueue <- func() {
		errChan <- f()
	}
	return <-errChan
}
CallErr queues function f on the main thread and returns an error returned by f.
package mainthread
import (
	"errors"
	"runtime"
)
var CallQueueCap = 16
var (
	callQueue chan func()
)
func init() {
	runtime.LockOSThread()
}
func checkRun() {
	if callQueue == nil {
		panic(errors.New("mainthread: did not call Run"))
	}
}
func Run(run func()) {
	callQueue = make(chan func(), CallQueueCap)
	done := make(chan struct{})
	go func() {
		run()
		done <- struct{}{}
	}()
	for {
		select {
		case f := <-callQueue:
			f()
		case <-done:
			return
		}
	}
}
func CallNonBlock(f func()) {
	checkRun()
	callQueue <- f
}
func Call(f func()) {
	checkRun()
	done := make(chan struct{})
	callQueue <- func() {
		f()
		done <- struct{}{}
	}
	<-done
}