Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mainthread.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import (
// The default value is 16 and should be good for 99% usecases.
var CallQueueCap = 16

var (
callQueue chan func()
)
var callQueue chan func()

func init() {
runtime.LockOSThread()
}

func checkRun() {
if callQueue == nil {
if !IsRunning() {
panic(errors.New("mainthread: did not call Run"))
}
}
Expand Down Expand Up @@ -48,6 +46,12 @@ func Run(run func()) {
}
}

// IsRunning returns true if the Run function has already
// been called and is running.
func IsRunning() bool {
return callQueue != nil
}

// CallNonBlock queues function f on the main thread and returns immediately. Does not wait until f
// finishes.
func CallNonBlock(f func()) {
Expand Down