Skip to content

Commit 48763cb

Browse files
authored
refactor(ipc): improve exit notify in event (#50)
Signed-off-by: Kevin Cui <bh@bugs.cc>
1 parent a162252 commit 48763cb

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

cmd/ovm/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func main() {
151151
}
152152

153153
func exit(exitCode int) {
154-
event.NotifyApp(event.Exit)
154+
event.NotifyExit()
155155
for _, clean := range cleans {
156156
clean()
157157
}

pkg/ipc/event/event.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type key string
2121
const (
2222
kApp key = "app"
2323
kError key = "error"
24+
kExit key = "exit"
2425
)
2526

2627
type app string
@@ -31,7 +32,6 @@ const (
3132
IgnitionProgress app = "IgnitionProgress"
3233
IgnitionDone app = "IgnitionDone"
3334
Ready app = "Ready"
34-
Exit app = "Exit"
3535
)
3636

3737
type datum struct {
@@ -91,7 +91,7 @@ func Setup(opt *cli.Context) error {
9191
}
9292
}
9393

94-
if datum.message == string(Exit) {
94+
if datum.name == kExit {
9595
waitDone <- struct{}{}
9696
return
9797
}
@@ -110,14 +110,6 @@ func NotifyApp(name app) {
110110
name: kApp,
111111
message: string(name),
112112
}
113-
114-
// wait for the event to be processed
115-
// Exit event indicates the main process exit
116-
if string(name) == string(Exit) {
117-
<-waitDone
118-
close(waitDone)
119-
e.channel.Close()
120-
}
121113
}
122114

123115
func NotifyError(err error) {
@@ -130,3 +122,18 @@ func NotifyError(err error) {
130122
message: err.Error(),
131123
}
132124
}
125+
126+
func NotifyExit() {
127+
if e == nil {
128+
return
129+
}
130+
131+
e.channel.In() <- &datum{
132+
name: kExit,
133+
message: "",
134+
}
135+
136+
<-waitDone
137+
close(waitDone)
138+
e.channel.Close()
139+
}

0 commit comments

Comments
 (0)