|
|
|
|
|
by the_gipsy
521 days ago
|
|
Consider this: ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
reader := ioContextReader(ctx, r)
...
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
ctx = context.WithValue(ctx, "hello", "world")
...
func(ctx context.Context) {
reader.Read() // does not time out after one second, does not contain hello/world.
...
}(ctx)
|
|
1) You're calling Read() directly and don't need to use functions that strictly accept io.Reader - then just implement ReadContext:
Otherwise, just wrap the ioContextReader with another ioContextReader: