NewPipeBuffer is a buffer that can have 1 read & 1 write at the same time. when read is faster write, immediately feed data to read after written
(ctx context.Context, block Block)
| 22 | // NewPipeBuffer is a buffer that can have 1 read & 1 write at the same time. |
| 23 | // when read is faster write, immediately feed data to read after written |
| 24 | func NewPipeBuffer(ctx context.Context, block Block) *PipeBuffer { |
| 25 | br := &PipeBuffer{ |
| 26 | ctx: ctx, |
| 27 | limit: int(block.Size()), |
| 28 | readSignal: make(chan struct{}, 1), |
| 29 | block: block, |
| 30 | } |
| 31 | return br |
| 32 | } |
| 33 | |
| 34 | func (br *PipeBuffer) Read(p []byte) (int, error) { |
| 35 | if err := br.ctx.Err(); err != nil { |