diff --git a/handler_stream.go b/handler_stream.go index e946163d..b3a219bb 100644 --- a/handler_stream.go +++ b/handler_stream.go @@ -20,10 +20,18 @@ import ( "net/http" ) +// NewClientStream creates a new ClientStream using the given +// StreamingHandlerConn. +func NewClientStream[Req any](conn StreamingHandlerConn) *ClientStream[Req] { + return &ClientStream[Req]{ + conn: conn, + } +} + // ClientStream is the handler's view of a client streaming RPC. // -// It's constructed as part of [Handler] invocation, but doesn't currently have -// an exported constructor. +// It's constructed as part of [Handler] invocation or it can be created using +// the NewClientStream constructor. type ClientStream[Req any] struct { conn StreamingHandlerConn initializer maybeInitializer @@ -86,10 +94,18 @@ func (c *ClientStream[Req]) Conn() StreamingHandlerConn { return c.conn } -// ServerStream is the handler's view of a server streaming RPC. +// NewServerStream creates a new ServerStream using the given +// StreamingHandlerConn. +func NewServerStream[Res any](conn StreamingHandlerConn) *ServerStream[Res] { + return &ServerStream[Res]{ + conn: conn, + } +} + +// ServerStream is the handler's view Client streaming RPC. // -// It's constructed as part of [Handler] invocation, but doesn't currently have -// an exported constructor. +// It's constructed as part of [Handler] invocation or it can be created using +// the NewServerStream constructor. type ServerStream[Res any] struct { conn StreamingHandlerConn } @@ -127,10 +143,17 @@ func (s *ServerStream[Res]) Conn() StreamingHandlerConn { return s.conn } +// NewBidiStream creates a new BidiStream using the given StreamingHandlerConn. +func NewBidiStream[Req, Res any](conn StreamingHandlerConn) *BidiStream[Req, Res] { + return &BidiStream[Req, Res]{ + conn: conn, + } +} + // BidiStream is the handler's view of a bidirectional streaming RPC. // -// It's constructed as part of [Handler] invocation, but doesn't currently have -// an exported constructor. +// It's constructed as part of [Handler] invocation or it can be created using +// the NewBidiStream constructor. type BidiStream[Req, Res any] struct { conn StreamingHandlerConn initializer maybeInitializer