Skip to content

Commit

Permalink
improve example a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jxsl13 committed Jul 6, 2024
1 parent d8fb971 commit 62b09b3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func asyncReadLine(ctx context.Context, wg *sync.WaitGroup, conn *econ.Conn, lin

func asyncWriteLine(ctx context.Context, wg *sync.WaitGroup, conn *econ.Conn, commandChan <-chan string) {
defer func() {
log.Println("closing command writer")
wg.Done()
log.Println("command writer closed")
}()
Expand All @@ -183,9 +184,17 @@ func asyncWriteLine(ctx context.Context, wg *sync.WaitGroup, conn *econ.Conn, co
case <-ctx.Done():
log.Printf("closing command writer: %v", ctx.Err())
return
case command := <-commandChan:
case command, ok := <-commandChan:
if !ok {
log.Println("command channel closed")
return
}
err = conn.WriteLine(command)
if err != nil {
if errors.Is(err, context.Canceled) {
log.Printf("closing command writer: %v", ctx.Err())
return
}
log.Printf("failed to write line: %v", err)
}
}
Expand Down

0 comments on commit 62b09b3

Please sign in to comment.