mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-13 03:59:23 +02:00
Switch to using goroutines rather than a select()
More complex code since now we have to synchronize between threads, but a good way to teach myself more about goroutines.
This commit is contained in:
@@ -2,39 +2,6 @@
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_IO_BUFFER_SIZE = 8192
|
||||
)
|
||||
|
||||
type BytesReader struct {
|
||||
Data []byte
|
||||
}
|
||||
|
||||
type Reader interface {
|
||||
ReadWithTimeout(b []byte, timeout time.Duration) (n int, err error)
|
||||
GetBuf() []byte
|
||||
}
|
||||
|
||||
func (self *BytesReader) Read(b []byte) (n int, err error) {
|
||||
if len(self.Data) == 0 {
|
||||
return 0, io.EOF
|
||||
}
|
||||
n = copy(b, self.Data)
|
||||
self.Data = self.Data[n:]
|
||||
return
|
||||
}
|
||||
|
||||
func (self *BytesReader) ReadWithTimeout(b []byte, timeout time.Duration) (n int, err error) {
|
||||
return self.Read(b)
|
||||
}
|
||||
|
||||
func (self *BytesReader) GetBuf() (ans []byte) {
|
||||
ans = self.Data
|
||||
self.Data = make([]byte, 0)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user