Skip to content

Commit b36b881

Browse files
committed
feat: add NewStreamWithContext
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent f2b59a0 commit b36b881

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

srpc/stream.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,24 @@ func (s *streamWithClose) Close() error {
6969
return err2
7070
}
7171

72+
// streamWithContext is a Stream with a wrapped Context function.
73+
type streamWithContext struct {
74+
Stream
75+
ctx context.Context
76+
}
77+
78+
// NewStreamWithContext wraps a Stream with a different context.
79+
func NewStreamWithContext(strm Stream, ctx context.Context) Stream {
80+
return &streamWithContext{Stream: strm, ctx: ctx}
81+
}
82+
83+
// Context returns the stream context.
84+
func (s *streamWithContext) Context() context.Context {
85+
return s.ctx
86+
}
87+
7288
// _ is a type assertion
73-
var _ Stream = (*streamWithClose)(nil)
89+
var (
90+
_ Stream = (*streamWithClose)(nil)
91+
_ Stream = (*streamWithContext)(nil)
92+
)

0 commit comments

Comments
 (0)