Skip to content

v0.3.0

Latest
Compare
Choose a tag to compare
@changkun changkun released this 20 Sep 15:43

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.