11import type { WritableStream , ReadableStream } from 'stream/web' ;
2- import type { ContextTimed } from '@matrixai/contexts' ;
2+ import type { ContextTimed , ContextTimedInput } from '@matrixai/contexts' ;
33import type {
44 HandlerType ,
55 JSONRPCRequestMessage ,
@@ -156,7 +156,7 @@ class RPCClient<M extends ClientManifest> {
156156 public async unaryCaller < I extends JSONValue , O extends JSONValue > (
157157 method : string ,
158158 parameters : I ,
159- ctx : Partial < ContextTimed > = { } ,
159+ ctx : Partial < ContextTimedInput > = { } ,
160160 ) : Promise < O > {
161161 const callerInterface = await this . duplexStreamCaller < I , O > ( method , ctx ) ;
162162 const reader = callerInterface . readable . getReader ( ) ;
@@ -191,7 +191,7 @@ class RPCClient<M extends ClientManifest> {
191191 public async serverStreamCaller < I extends JSONValue , O extends JSONValue > (
192192 method : string ,
193193 parameters : I ,
194- ctx : Partial < ContextTimed > = { } ,
194+ ctx : Partial < ContextTimedInput > = { } ,
195195 ) : Promise < ReadableStream < O > > {
196196 const callerInterface = await this . duplexStreamCaller < I , O > ( method , ctx ) ;
197197 const writer = callerInterface . writable . getWriter ( ) ;
@@ -219,7 +219,7 @@ class RPCClient<M extends ClientManifest> {
219219 @ready ( new rpcErrors . ErrorRPCDestroyed ( ) )
220220 public async clientStreamCaller < I extends JSONValue , O extends JSONValue > (
221221 method : string ,
222- ctx : Partial < ContextTimed > = { } ,
222+ ctx : Partial < ContextTimedInput > = { } ,
223223 ) : Promise < {
224224 output : Promise < O > ;
225225 writable : WritableStream < I > ;
@@ -252,7 +252,7 @@ class RPCClient<M extends ClientManifest> {
252252 @ready ( new rpcErrors . ErrorRPCDestroyed ( ) )
253253 public async duplexStreamCaller < I extends JSONValue , O extends JSONValue > (
254254 method : string ,
255- ctx : Partial < ContextTimed > = { } ,
255+ ctx : Partial < ContextTimedInput > = { } ,
256256 ) : Promise < RPCStream < O , I > > {
257257 const abortController = new AbortController ( ) ;
258258 const signal = abortController . signal ;
@@ -270,11 +270,14 @@ class RPCClient<M extends ClientManifest> {
270270 if ( ctx . signal . aborted ) abortHandler ( ) ;
271271 ctx . signal . addEventListener ( 'abort' , abortHandler ) ;
272272 }
273- const timer =
274- ctx . timer ??
275- new Timer ( {
276- delay : this . streamKeepAliveTimeoutTime ,
273+ let timer : Timer ;
274+ if ( ! ( ctx . timer instanceof Timer ) ) {
275+ timer = new Timer ( {
276+ delay : ctx . timer ?? this . streamKeepAliveTimeoutTime ,
277277 } ) ;
278+ } else {
279+ timer = ctx . timer ;
280+ }
278281 const cleanUp = ( ) => {
279282 // Clean up the timer and signal
280283 if ( ctx . timer == null ) timer . cancel ( timerCleanupReasonSymbol ) ;
0 commit comments