grpc-js: handle http2 backpressure in server

This commit adds backpressure handling code to the
ServerWritableStream implementation.
This commit is contained in:
cjihrig 2019-04-28 11:25:31 -04:00
parent 79544366be
commit a6e2edce9a
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
1 changed files with 10 additions and 3 deletions

View File

@ -150,16 +150,23 @@ export class ServerWritableStreamImpl<RequestType, ResponseType> extends
this.call.sendMetadata(responseMetadata);
}
async _write(chunk: ResponseType, encoding: string, callback: Function) {
async _write(
chunk: ResponseType, encoding: string,
// tslint:disable-next-line:no-any
callback: (...args: any[]) => void) {
try {
const response = await this.call.serializeMessage(chunk);
this.call.write(response);
if (!this.call.write(response)) {
this.call.once('drain', callback);
return;
}
} catch (err) {
err.code = Status.INTERNAL;
this.emit('error', err);
}
callback(null);
callback();
}
_final(callback: Function): void {