@@ -70,6 +70,17 @@ function getSystemErrorName(errno: number): string {
70
70
71
71
export type Deadline = Date | number ;
72
72
73
+ function getMinDeadline ( deadlineList : Deadline [ ] ) : Deadline {
74
+ let minValue : number = Infinity ;
75
+ for ( const deadline of deadlineList ) {
76
+ const deadlineMsecs = deadline instanceof Date ? deadline . getTime ( ) : deadline ;
77
+ if ( deadlineMsecs < minValue ) {
78
+ minValue = deadlineMsecs ;
79
+ }
80
+ }
81
+ return minValue ;
82
+ }
83
+
73
84
export interface CallStreamOptions {
74
85
deadline : Deadline ;
75
86
flags : number ;
@@ -235,6 +246,8 @@ export class Http2CallStream implements Call {
235
246
236
247
private internalError : SystemError | null = null ;
237
248
249
+ private configDeadline : Deadline = Infinity ;
250
+
238
251
constructor (
239
252
private readonly methodName : string ,
240
253
private readonly channel : ChannelImplementation ,
@@ -675,15 +688,14 @@ export class Http2CallStream implements Call {
675
688
}
676
689
677
690
getDeadline ( ) : Deadline {
691
+ const deadlineList = [ this . options . deadline ] ;
678
692
if ( this . options . parentCall && this . options . flags & Propagate . DEADLINE ) {
679
- const parentDeadline = this . options . parentCall . getDeadline ( ) ;
680
- const selfDeadline = this . options . deadline ;
681
- const parentDeadlineMsecs = parentDeadline instanceof Date ? parentDeadline . getTime ( ) : parentDeadline ;
682
- const selfDeadlineMsecs = selfDeadline instanceof Date ? selfDeadline . getTime ( ) : selfDeadline ;
683
- return Math . min ( parentDeadlineMsecs , selfDeadlineMsecs ) ;
684
- } else {
685
- return this . options . deadline ;
693
+ deadlineList . push ( this . options . parentCall . getDeadline ( ) ) ;
694
+ }
695
+ if ( this . configDeadline ) {
696
+ deadlineList . push ( this . configDeadline ) ;
686
697
}
698
+ return getMinDeadline ( deadlineList ) ;
687
699
}
688
700
689
701
getCredentials ( ) : CallCredentials {
@@ -710,6 +722,10 @@ export class Http2CallStream implements Call {
710
722
return this . options . host ;
711
723
}
712
724
725
+ setConfigDeadline ( configDeadline : Deadline ) {
726
+ this . configDeadline = configDeadline ;
727
+ }
728
+
713
729
startRead ( ) {
714
730
/* If the stream has ended with an error, we should not emit any more
715
731
* messages and we should communicate that the stream has ended */
0 commit comments