mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
Use signal to catch SIGINT and SIGTERM
This commit is contained in:
parent
6f1799b1c6
commit
ee23301538
@ -5,7 +5,10 @@ import (
|
|||||||
"github.com/hajimehoshi/go-ebiten/graphics"
|
"github.com/hajimehoshi/go-ebiten/graphics"
|
||||||
"github.com/hajimehoshi/go-ebiten/ui"
|
"github.com/hajimehoshi/go-ebiten/ui"
|
||||||
"github.com/hajimehoshi/go-ebiten/ui/cocoa"
|
"github.com/hajimehoshi/go-ebiten/ui/cocoa"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -61,6 +64,8 @@ func main() {
|
|||||||
|
|
||||||
u.RunMainLoop()
|
u.RunMainLoop()
|
||||||
|
|
||||||
|
s := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(s, os.Interrupt, syscall.SIGTERM)
|
||||||
for {
|
for {
|
||||||
u.PollEvents()
|
u.PollEvents()
|
||||||
select {
|
select {
|
||||||
@ -74,6 +79,8 @@ func main() {
|
|||||||
after := time.After(time.Duration(int64(time.Second) / 120))
|
after := time.After(time.Duration(int64(time.Second) / 120))
|
||||||
u.PollEvents()
|
u.PollEvents()
|
||||||
<-after
|
<-after
|
||||||
|
case <-s:
|
||||||
|
return
|
||||||
case <-quit:
|
case <-quit:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user