From be665a35265f56273c350bed5eeb00c1a85ab457 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 9 Jun 2018 13:36:35 +0900 Subject: [PATCH] ui: Better way to avoid blocking Fixes #625 --- internal/ui/ui_js.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 2b17c47fd..bc3b58258 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -208,16 +208,17 @@ func (u *userInterface) loop(g GraphicsContext) error { var cf js.Callback f = func([]js.Value) { if err := u.update(g); err != nil { - go func() { - ch <- err - close(ch) - }() + ch <- err + close(ch) return } js.Global.Get("window").Call("requestAnimationFrame", cf) } cf = js.NewCallback(f) - f(nil) + // Call f asyncly to be async since ch is used in f. + go func() { + f(nil) + }() return <-ch }