Skip to content

Commit

Permalink
Add constructors for streams
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Apr 20, 2024
1 parent f7f3814 commit 2972c08
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions handler_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2972c08

Please sign in to comment.