~whereswaldon/gio-x

23832138673ed6a3814ffe70c8292403943fbdfe — Jack Mordaunt 1 year, 3 months ago cf97c3d
eventx: handle nil queues

This commit ensure that nil'ing out a queue, which is a valid
convention in Gio, does not cause a panic in the Spy.

The problem is amplified due to the fact that the nil'ing context
is completely unrelated to the Spy context, making if very easy
to introduce panics.

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
1 files changed, 7 insertions(+), 4 deletions(-)

M eventx/spy.go
M eventx/spy.go => eventx/spy.go +7 -4
@@ 43,7 43,6 @@ func Enspy(gtx layout.Context) (*Spy, layout.Context) {
	spy := &Spy{Queue: gtx.Queue}
	gtx.Queue = spy
	return spy, gtx

}

// Events returns the events for a given tag from the wrapped Queue.


@@ 76,8 75,12 @@ func Combine(gtx layout.Context, queue event.Queue) layout.Context {
}

// Events returns the combined results of the two queues.
func (u CombinedQueue) Events(tag event.Tag) []event.Event {
	out := u.A.Events(tag)
	out = append(out, u.B.Events(tag)...)
func (u CombinedQueue) Events(tag event.Tag) (out []event.Event) {
	if u.A != nil {
		out = append(out, u.A.Events(tag)...)
	}
	if u.B != nil {
		out = append(out, u.B.Events(tag)...)
	}
	return out
}