Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ipc): improve exit notify in event #50

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}