@@ -203,8 +203,6 @@ function canceled(): Error {
203
203
error . name = error . message ;
204
204
return error ;
205
205
}
206
- // 默认 30s 超时
207
- export const DEFAULT_TIMEOUT_MS = 30000 ;
208
206
209
207
export class RPCProtocol implements IRPCProtocol {
210
208
private readonly _protocol : IMessagePassingProtocol ;
@@ -281,12 +279,13 @@ export class RPCProtocol implements IRPCProtocol {
281
279
const msg = MessageIO . serializeRequest ( callId , rpcId , methodName , args ) ;
282
280
283
281
this . _protocol . send ( msg ) ;
284
- // 设置超时回调
285
- const timeoutHandle = setTimeout ( ( ) => {
286
- this . _handleTimeout ( callId ) ;
287
- } , this . _protocol . timeout || DEFAULT_TIMEOUT_MS ) ;
288
-
289
- this . _timeoutHandles . set ( callId , timeoutHandle ) ;
282
+ // 设置超时回调, -1 即不配置超时时间
283
+ if ( this . _protocol . timeout && this . _protocol . timeout !== - 1 ) {
284
+ const timeoutHandle = setTimeout ( ( ) => {
285
+ this . _handleTimeout ( callId ) ;
286
+ } , this . _protocol . timeout ) ;
287
+ this . _timeoutHandles . set ( callId , timeoutHandle ) ;
288
+ }
290
289
291
290
return result . promise ;
292
291
}
@@ -411,6 +410,6 @@ export class RPCProtocol implements IRPCProtocol {
411
410
this . _pendingRPCReplies . delete ( callId ) ;
412
411
this . _timeoutHandles . delete ( callId ) ;
413
412
414
- pendingReply . reject ( 'RPC Timeout' ) ;
413
+ pendingReply . reject ( new Error ( 'RPC Timeout: ' + callId ) ) ;
415
414
}
416
415
}
0 commit comments