Skip to content

Commit

Permalink
Add async service protocol
Browse files Browse the repository at this point in the history
This allows to implement a server using either synchronous or asynchronous functions
  • Loading branch information
MiLk committed Sep 6, 2024
1 parent 6c37ccf commit 58f6cfc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion protoc-gen-twirpy/generator/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ class {{.Name}}ServiceProtocol(Protocol):
def {{.Name}}(self, ctx: Context, request: {{.QualifiedInput}}) -> {{.QualifiedOutput}}: ...
{{- end }}
class Async{{.Name}}ServiceProtocol(Protocol):
{{- range .Methods }}
async def {{.Name}}(self, ctx: Context, request: {{.QualifiedInput}}) -> {{.QualifiedOutput}}: ...
{{- end }}
class {{.Name}}Server(TwirpServer):
def __init__(
self,
*,
service: {{.Name}}ServiceProtocol,
service: {{.Name}}ServiceProtocol | Async{{.Name}}ServiceProtocol,
server_path_prefix: str = "/twirp"
):
super().__init__(service=service)
Expand Down

0 comments on commit 58f6cfc

Please sign in to comment.