Skip to content

Commit

Permalink
refactor(ipc): improve exit notify in event (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Cui <[email protected]>
  • Loading branch information
BlackHole1 authored Jul 15, 2024
1 parent a162252 commit 48763cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/ovm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func main() {
}

func exit(exitCode int) {
event.NotifyApp(event.Exit)
event.NotifyExit()
for _, clean := range cleans {
clean()
}
Expand Down
27 changes: 17 additions & 10 deletions pkg/ipc/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type key string
const (
kApp key = "app"
kError key = "error"
kExit key = "exit"
)

type app string
Expand All @@ -31,7 +32,6 @@ const (
IgnitionProgress app = "IgnitionProgress"
IgnitionDone app = "IgnitionDone"
Ready app = "Ready"
Exit app = "Exit"
)

type datum struct {
Expand Down Expand Up @@ -91,7 +91,7 @@ func Setup(opt *cli.Context) error {
}
}

if datum.message == string(Exit) {
if datum.name == kExit {
waitDone <- struct{}{}
return
}
Expand All @@ -110,14 +110,6 @@ func NotifyApp(name app) {
name: kApp,
message: string(name),
}

// wait for the event to be processed
// Exit event indicates the main process exit
if string(name) == string(Exit) {
<-waitDone
close(waitDone)
e.channel.Close()
}
}

func NotifyError(err error) {
Expand All @@ -130,3 +122,18 @@ func NotifyError(err error) {
message: err.Error(),
}
}

func NotifyExit() {
if e == nil {
return
}

e.channel.In() <- &datum{
name: kExit,
message: "",
}

<-waitDone
close(waitDone)
e.channel.Close()
}

0 comments on commit 48763cb

Please sign in to comment.