Skip to content

Commit

Permalink
Add grpc-es closer
Browse files Browse the repository at this point in the history
  • Loading branch information
kanziw committed Aug 13, 2024
1 parent fd610aa commit bf93f03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-es/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kanziw/grpc-es",
"type": "module",
"version": "0.2.2",
"version": "0.2.3",
"description": "A collection of grpc libraries using connect-es",
"repository": {
"type": "git",
Expand Down
14 changes: 13 additions & 1 deletion packages/grpc-es/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Interceptor } from './types.js'
export class GrpcEsServer {
private interceptors: Interceptor[] = []
private services: { service: ServiceType; implementation: ServiceImpl<ServiceType> }[] = []
private http2Server: http2.Http2Server | null = null

constructor(private options?: Partial<UniversalHandlerOptions>) {}

Expand Down Expand Up @@ -37,7 +38,7 @@ export class GrpcEsServer {
}

listenAndServe(port: number): void {
http2
this.http2Server = http2
.createServer(
connectNodeAdapter({
routes: (router) => {
Expand All @@ -49,6 +50,17 @@ export class GrpcEsServer {
)
.listen(port)
}

async close(): Promise<void> {
const server = this.http2Server
if (!server) {
return
}

return new Promise((resolve, reject) => {
server.close((err) => (err ? reject(err) : resolve()))
})
}
}

function makeUnimplementedService<Service extends ServiceType>(service: Service): ServiceImpl<Service> {
Expand Down

0 comments on commit bf93f03

Please sign in to comment.