mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 18:07:51 +08:00
edit: fix async_reader
This commit is contained in:
parent
38e0df7b58
commit
ff78be04db
|
@ -71,24 +71,18 @@ func (ar *AsyncReader) Start() {
|
|||
ar.ackCtrl <- true
|
||||
return
|
||||
} else {
|
||||
ReadRune:
|
||||
for {
|
||||
r, _, err := ar.bufrd.ReadRune()
|
||||
switch err {
|
||||
case nil:
|
||||
// Deadlock when consumer goroutine is in .Quit!
|
||||
ar.ch <- r
|
||||
case io.EOF:
|
||||
return
|
||||
default:
|
||||
// BUG(xiaq): AsyncReader relies on the undocumented fact
|
||||
// that (*os.File).Read returns an *os.File.PathError
|
||||
e := err.(*os.PathError).Err
|
||||
if e == syscall.EWOULDBLOCK || e == syscall.EAGAIN {
|
||||
break ReadRune
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
r, _, err := ar.bufrd.ReadRune()
|
||||
switch err {
|
||||
case nil:
|
||||
ar.ch <- r
|
||||
case io.EOF:
|
||||
return
|
||||
default:
|
||||
// BUG(xiaq): AsyncReader relies on the undocumented fact
|
||||
// that (*os.File).Read returns an *os.File.PathError
|
||||
e := err.(*os.PathError).Err
|
||||
if e != syscall.EWOULDBLOCK && e != syscall.EAGAIN {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +94,10 @@ func (ar *AsyncReader) Quit() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
select {
|
||||
case <-ar.ch:
|
||||
default:
|
||||
}
|
||||
<-ar.ackCtrl
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user