Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add grpc-es closer #27

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading