@@ -53,7 +53,10 @@ export interface SandboxRpcOptions {
5353 * passes plain objects through untouched.
5454 */
5555 post : ( message : Record < string , unknown > ) => void ;
56- /** Default per-request timeout. 10s matches the old capture-png ceiling. */
56+ /**
57+ * Default per-request timeout. 10s matches the old capture-png ceiling.
58+ * Requests with no upper bound on their duration pass `timeoutMs: null`.
59+ */
5760 defaultTimeoutMs ?: number ;
5861 /** Override id minting (tests inject a deterministic counter). */
5962 generateId ?: ( ) => string ;
@@ -70,7 +73,8 @@ function defaultGenerateId(): string {
7073interface Pending {
7174 resolve : ( value : unknown ) => void ;
7275 reject : ( error : Error ) => void ;
73- timer : ReturnType < typeof setTimeout > ;
76+ /** Unset for requests with `timeoutMs: null`. */
77+ timer ?: ReturnType < typeof setTimeout > ;
7478}
7579
7680export class SandboxRpc {
@@ -90,19 +94,27 @@ export class SandboxRpc {
9094 /**
9195 * Send a request and await the peer's reply. Rejects if the peer reports
9296 * an error, has no handler for `kind`, or doesn't reply within the timeout.
97+ * `timeoutMs: null` waits for the reply until the channel is disposed.
9398 */
94- request < T = unknown > ( kind : string , payload ?: unknown , opts ?: { timeoutMs ?: number } ) : Promise < T > {
99+ request < T = unknown > (
100+ kind : string ,
101+ payload ?: unknown ,
102+ opts ?: { timeoutMs ?: number | null }
103+ ) : Promise < T > {
95104 if ( this . #disposed) {
96105 return Promise . reject ( new Error ( 'sandbox channel closed' ) ) ;
97106 }
98107 const requestId = this . #generateId( ) ;
99- const timeoutMs = opts ?. timeoutMs ?? this . #defaultTimeoutMs;
108+ const timeoutMs = opts ?. timeoutMs === undefined ? this . #defaultTimeoutMs : opts . timeoutMs ;
100109 return new Promise < T > ( ( resolve , reject ) => {
101- const timer = setTimeout ( ( ) => {
102- if ( this . #pending. delete ( requestId ) ) {
103- reject ( new Error ( `sandbox request "${ kind } " timed out after ${ timeoutMs } ms` ) ) ;
104- }
105- } , timeoutMs ) ;
110+ const timer =
111+ timeoutMs === null
112+ ? undefined
113+ : setTimeout ( ( ) => {
114+ if ( this . #pending. delete ( requestId ) ) {
115+ reject ( new Error ( `sandbox request "${ kind } " timed out after ${ timeoutMs } ms` ) ) ;
116+ }
117+ } , timeoutMs ) ;
106118 this . #pending. set ( requestId , {
107119 resolve : resolve as ( value : unknown ) => void ,
108120 reject,
0 commit comments