Merge pull request #768 from murgatroid99/grpc-js_deadline_filter_promise_finish

grpc-js: deadline filter: reject promise if call ends
This commit is contained in:
Michael Lumish 2019-03-08 10:01:42 -08:00 committed by GitHub
commit 8704950a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -60,9 +60,16 @@ export class DeadlineFilter extends BaseFilter implements Filter {
resolve(metadata);
this.channel.removeListener(
'connectivityStateChanged', handleStateChange);
this.callStream.removeListener('status', handleStatus);
}
};
const handleStatus = () => {
reject(new Error('Call ended'));
this.channel.removeListener(
'connectivityStateChanged', handleStateChange);
};
this.channel.on('connectivityStateChanged', handleStateChange);
this.callStream.once('status', handleStatus);
}
})
.then((finalMetadata: Metadata) => {

View File

@ -46,6 +46,7 @@ export class Http2SubChannel extends EventEmitter implements SubChannel {
userAgent: string, channelArgs: Partial<ChannelOptions>) {
super();
this.session = http2.connect(target, connectionOptions);
this.session.unref();
this.session.on('connect', () => {
this.emit('connect');
});