Skip to content

Commit e579adb

Browse files
changkunnigeltao
authored andcommitted
app: allow app.Main to return on Windows
Fixes golang/go#49499 Change-Id: Ia65b61b9e0707321439ea85d06bac5ed507b58c7 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/369196 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Trust: Dmitri Shuralyov <[email protected]> Run-TryBot: Changkun Ou <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 447654d commit e579adb

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

app/android.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,12 @@ func mainUI(vm, jniEnv, ctx uintptr) error {
287287

288288
donec := make(chan struct{})
289289
go func() {
290+
// close the donec channel in a defer statement
291+
// so that we could still be able to return even
292+
// if mainUserFn panics.
293+
defer close(donec)
294+
290295
mainUserFn(theApp)
291-
close(donec)
292296
}()
293297

294298
var pixelsPerPt float32

app/shiny.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,23 @@ func main(f func(a App)) {
3838
}
3939
}()
4040

41-
go f(theApp)
41+
donec := make(chan struct{})
42+
go func() {
43+
// close the donec channel in a defer statement
44+
// so that we could still be able to return even
45+
// if f panics.
46+
defer close(donec)
47+
48+
f(theApp)
49+
}()
4250

4351
for {
44-
theApp.Send(convertEvent(w.NextEvent()))
52+
select {
53+
case <-donec:
54+
return
55+
default:
56+
theApp.Send(convertEvent(w.NextEvent()))
57+
}
4558
}
4659
})
4760
}

app/x11.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ func main(f func(App)) {
5252

5353
donec := make(chan struct{})
5454
go func() {
55+
// close the donec channel in a defer statement
56+
// so that we could still be able to return even
57+
// if f panics.
58+
defer close(donec)
59+
5560
f(theApp)
56-
close(donec)
5761
}()
5862

5963
// TODO: can we get the actual vsync signal?

0 commit comments

Comments
 (0)