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

grpc-js: add await/async on method that return promise #2376

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/grpc-js/src/server-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,10 @@ export class Http2ServerCallStream<

let pushedEnd = false;

const maybePushEnd = () => {
const maybePushEnd = async () => {
if (!pushedEnd && readsDone && !pendingMessageProcessing) {
pushedEnd = true;
this.pushOrBufferMessage(readable, null);
await this.pushOrBufferMessage(readable, null);
}
};

Expand Down Expand Up @@ -844,16 +844,16 @@ export class Http2ServerCallStream<
// Just return early
if (!decompressedMessage) return;

this.pushOrBufferMessage(readable, decompressedMessage);
await this.pushOrBufferMessage(readable, decompressedMessage);
}
pendingMessageProcessing = false;
this.stream.resume();
maybePushEnd();
await maybePushEnd();
});

this.stream.once('end', () => {
this.stream.once('end', async () => {
readsDone = true;
maybePushEnd();
await maybePushEnd();
});
}

Expand All @@ -877,16 +877,16 @@ export class Http2ServerCallStream<
return this.canPush;
}

private pushOrBufferMessage(
private async pushOrBufferMessage(
readable:
| ServerReadableStream<RequestType, ResponseType>
| ServerDuplexStream<RequestType, ResponseType>,
messageBytes: Buffer | null
): void {
): Promise<void> {
if (this.isPushPending) {
this.bufferedMessages.push(messageBytes);
} else {
this.pushMessage(readable, messageBytes);
await this.pushMessage(readable, messageBytes);
}
}

Expand Down Expand Up @@ -939,7 +939,7 @@ export class Http2ServerCallStream<
this.isPushPending = false;

if (this.bufferedMessages.length > 0) {
this.pushMessage(
await this.pushMessage(
readable,
this.bufferedMessages.shift() as Buffer | null
);
Expand Down