Fixed ws dial input error being dropped
This commit is contained in:
1 parent
02e3d910a2
commit
b714ee14d5
2 files changed
+38
-1
No files matched your search
@@ -321,14 +321,17 @@ func interact(
|
||||
}()
|
||||
|
||||
// Reading input can't be interrupted, so it has a goroutine of its own,
|
||||
// left blocked if ctx is cancelled first.
|
||||
// left blocked if ctx is cancelled first. Its error, if any, is sent
|
||||
// before lines is closed.
|
||||
lines := make(chan string)
|
||||
inputErr := make(chan error, 1)
|
||||
go func() {
|
||||
defer close(lines)
|
||||
scanner := bufio.NewScanner(input)
|
||||
for scanner.Scan() {
|
||||
lines <- scanner.Text()
|
||||
}
|
||||
inputErr <- scanner.Err()
|
||||
}()
|
||||
|
||||
for {
|
||||
@@ -339,6 +342,11 @@ func interact(
|
||||
return err
|
||||
case line, ok := <-lines:
|
||||
if !ok {
|
||||
err := <-inputErr
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading input: %w", err)
|
||||
}
|
||||
|
||||
// The end of input: stop sending, keep listening.
|
||||
lines = nil
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user