Source File
ctxio.go
Belonging Package
github.com/jbenet/go-context/io
func ( context.Context, io.Writer) *ctxWriter {
if == nil {
= context.Background()
}
return &ctxWriter{ctx: , w: }
}
func ( *ctxWriter) ( []byte) (int, error) {
:= make([]byte, len())
copy(, )
:= make(chan ioret, 1)
go func() {
, := .w.Write()
<- ioret{, }
close()
}()
select {
case := <-:
return .n, .err
case <-.ctx.Done():
return 0, .ctx.Err()
}
}
type Reader interface {
io.Reader
}
type ctxReader struct {
r io.Reader
ctx context.Context
}
func ( context.Context, io.Reader) *ctxReader {
return &ctxReader{ctx: , r: }
}
func ( *ctxReader) ( []byte) (int, error) {
:= make([]byte, len())
:= make(chan ioret, 1)
go func() {
, := .r.Read()
<- ioret{, }
close()
}()
select {
case := <-:
copy(, )
return .n, .err
case <-.ctx.Done():
return 0, .ctx.Err()
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |