Skip to content

Commit 5fbe12f

Browse files
committed
fix: end logging before terminate // fix #51
1 parent b0721a7 commit 5fbe12f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Diff for: cmd/subtitle.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ func downloadSubtitles(cmd *cobra.Command, args []string) {
7575
}).Fatal("Media limit exceeded")
7676
}
7777

78-
c := notify.AsyncLogger()
79-
defer close(c)
78+
c, done := notify.AsyncLogger()
8079

8180
numsubs, err := app.DownloadSubtitles(media, config.Languages(), c)
8281

82+
close(c)
83+
<-done
84+
8385
if err != nil {
8486
log.WithError(err).Fatal("Download incomplete")
8587
}

Diff for: notify/util.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import (
55
)
66

77
// AsyncLogger receives notification entries from a channel and logs them
8-
func AsyncLogger() chan<- *Entry {
8+
func AsyncLogger() (chan<- *Entry, chan bool) {
99
c := make(chan *Entry)
10-
go func() {
10+
d := make(chan bool, 1)
11+
go func(c <-chan *Entry, d chan<- bool) {
12+
defer func() {
13+
d <- true
14+
}()
1115
for e := range c {
1216
ctx := log.WithFields(log.Fields(e.Fields))
1317
switch e.Level {
@@ -25,8 +29,8 @@ func AsyncLogger() chan<- *Entry {
2529
ctx.Error(e.Message)
2630
}
2731
}
28-
}()
29-
return c
32+
}(c, d)
33+
return c, d
3034
}
3135

3236
// AsyncDiscard discards all notifications

0 commit comments

Comments
 (0)