Most GUI toolkits require you to use one thread. It doesn't matter which thread, so long as you only use one thread.
Cocoa, however, absolutely demands you use the very first OS thread created, called the "main thread", and provides no way to change which thread is used.
This basically means that instead of you saying
func main() {
w := ui.NewWindow(blah blah blah)
blah blah blah
for { event loop }
}
you must instead say
func myMain() {
w := ui.NewWindow(blah blah blah)
blah blah blah
for { event loop }
}
func main() {
ui.Go(myMain)
}
and ui.Go()
runs myMain()
as a goroutine. Or also
func main() {
go myMain()
ui.Go()
}
This also means you cannot use go test
with package ui, as go test
provides its own main()
.
I don't know if I want to do this; I'm not sure what other people think. I know it would be similar to http.ListenAndServe()
, but.
Which do people generally prefer?