Skip to content

Releases: golang-design/mainthread

v0.3.0

20 Sep 15:43
Compare
Choose a tag to compare

Support capturing panics. Here is a documentation of usage:

If a given function triggers a panic and is called via mainthread.Call,
the panic will propagate to the same goroutine. One can capture
that panic, when possible:

defer func() {
	if r := recover(); r != nil {
		println(r)
	}
}()

mainthread.Call(func() { ... }) // if panic

If the given function triggers a panic, and called via mainthread.Go,
then the panic will be cached internally, until a call to the Error() method:

mainthread.Go(func() { ... }) // if panics

// ... do stuff ...

if err := mainthread.Error(); err != nil { // can be captured here.
	println(err)
}

Note that a panic happens before mainthread.Error() returning the
panicked error. If one needs to guarantee mainthread.Error() indeed
captured the panic, a dummy function can be used as synchornization:

mainthread.Go(func() { panic("die") })	// if panics
mainthread.Call(func() {}) 				// for execution synchronization
err := mainthread.Error()				// err must be non-nil

It is possible to cache up to a maximum of 42 panicked errors.
More errors are ignored.

v0.2.1

21 Feb 07:38
Compare
Choose a tag to compare
  • Documentation updates and fixes

v0.2.0

20 Feb 21:58
Compare
Choose a tag to compare
  • Add mainthread.Go
  • Documentation updates
  • Switch to MIT license

v0.1.0

21 Jan 12:25
Compare
Choose a tag to compare

Package mainthead schedules function to be called on the main thread.