From 53095344271fa0b6ac41c60d4ce154dec04ae888 Mon Sep 17 00:00:00 2001 From: Brian Chen Date: Fri, 21 Jun 2019 17:05:44 -0700 Subject: [PATCH] add comments and reformat --- dev/src/watch.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/dev/src/watch.ts b/dev/src/watch.ts index 8962770d5..739db9753 100644 --- a/dev/src/watch.ts +++ b/dev/src/watch.ts @@ -523,14 +523,15 @@ abstract class Watch { this.currentStream = backendStream; this.currentStream!.on('data', (proto: api.IListenResponse) => { this.onData(proto); - }).on('error', err => { - this.maybeReopenStream(err); - }); - this.currentStream!.on('end', () => { - const err = new GrpcError('Stream ended unexpectedly'); - err.code = GRPC_STATUS_CODE.UNKNOWN; - this.maybeReopenStream(err); - }); + }) + .on('error', err => { + this.maybeReopenStream(err); + }) + .on('end', () => { + const err = new GrpcError('Stream ended unexpectedly'); + err.code = GRPC_STATUS_CODE.UNKNOWN; + this.maybeReopenStream(err); + }); this.currentStream!.resume(); }); }) @@ -538,7 +539,11 @@ abstract class Watch { this.closeStream(err); }); } - + /** + * Handles 'data' events and closes the stream if the response type is + * invalid. + * @private + */ private onData(proto: api.IListenResponse): void { if (proto.targetChange) { logger('Watch.onSnapshot', this.requestTag, 'Processing target change');