@@ -125,7 +125,7 @@ export class BrowserService {
125125 await this . db . put ( owner , "browsers" , session ) ;
126126 return this . decorate ( owner , session ) ;
127127 }
128- async create ( owner : string , url : string ) {
128+ async create ( owner : string , url : string , signal ?: AbortSignal ) {
129129 const id = randomUUID ( ) ;
130130 // Record ownership before calling the worker, including when its response is lost.
131131 await this . db . put ( owner , "browsers" , {
@@ -135,7 +135,7 @@ export class BrowserService {
135135 status : "idle" ,
136136 updatedAt : new Date ( ) . toISOString ( ) ,
137137 } ) ;
138- return this . reopen ( owner , id , url ) ;
138+ return this . reopen ( owner , id , url , signal ) ;
139139 }
140140 private async openOwned ( owner : string , id : string , url ?: string , signal ?: AbortSignal ) {
141141 const value = await this . get ( owner , id ) ;
@@ -144,6 +144,7 @@ export class BrowserService {
144144 const response = await this . request ( "/sessions" , { id, url : target } , signal ) ;
145145 return await this . save ( owner , await response . json ( ) , id ) ;
146146 } catch ( error ) {
147+ signal ?. throwIfAborted ( ) ;
147148 await this . save (
148149 owner ,
149150 { ...value , url : target , status : "error" , updatedAt : new Date ( ) . toISOString ( ) } ,
@@ -152,8 +153,8 @@ export class BrowserService {
152153 throw error ;
153154 }
154155 }
155- reopen ( owner : string , id : string , url ?: string ) {
156- return this . serial ( id , ( ) => this . openOwned ( owner , id , url ) ) ;
156+ reopen ( owner : string , id : string , url ?: string , signal ?: AbortSignal ) {
157+ return this . serial ( id , ( ) => this . openOwned ( owner , id , url , signal ) ) ;
157158 }
158159 navigate ( owner : string , id : string , url : string ) {
159160 return this . reopen ( owner , id , url ) ;
@@ -181,11 +182,13 @@ export class BrowserService {
181182 read ( owner : string , id : string ) {
182183 return this . serial ( id , ( ) => this . readOwned ( owner , id ) ) ;
183184 }
184- async observe ( owner : string , url : string , existingId ?: string ) {
185- const id = existingId ?? ( await this . create ( owner , url ) ) . id ;
185+ async observe ( owner : string , url : string , existingId ?: string , signal ?: AbortSignal ) {
186+ const id = existingId ?? ( await this . create ( owner , url , signal ) ) . id ;
186187 return this . serial ( id , async ( ) => {
187- if ( existingId ) await this . openOwned ( owner , id , url ) ;
188- return { sessionId : id , ...( await this . readOwned ( owner , id ) ) } ;
188+ signal ?. throwIfAborted ( ) ;
189+ if ( existingId ) await this . openOwned ( owner , id , url , signal ) ;
190+ signal ?. throwIfAborted ( ) ;
191+ return { sessionId : id , ...( await this . readOwned ( owner , id , signal ) ) } ;
189192 } ) ;
190193 }
191194 async observeForThread ( owner : string , threadId : string , url : string , signal ?: AbortSignal ) {
0 commit comments