@@ -33,9 +33,9 @@ function isTelemetryEnabled(): boolean {
3333}
3434
3535export interface IGitpodAPI {
36- getWorkspace ( workspaceId : string ) : Promise < Workspace > ;
36+ getWorkspace ( workspaceId : string , signal ?: AbortSignal ) : Promise < Workspace > ;
3737 startWorkspace ( workspaceId : string ) : Promise < Workspace > ;
38- getOwnerToken ( workspaceId : string ) : Promise < string > ;
38+ getOwnerToken ( workspaceId : string , signal ?: AbortSignal ) : Promise < string > ;
3939 getSSHKeys ( ) : Promise < SSHKey [ ] > ;
4040 sendHeartbeat ( workspaceId : string ) : Promise < void > ;
4141 sendDidClose ( workspaceId : string ) : Promise < void > ;
@@ -93,11 +93,11 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
9393 }
9494
9595
96- async getWorkspace ( workspaceId : string ) : Promise < Workspace > {
96+ async getWorkspace ( workspaceId : string , signal ?: AbortSignal ) : Promise < Workspace > {
9797 return this . _wrapError ( this . _workaroundGoAwayBug ( async ( ) => {
9898 const response = await this . workspaceService . getWorkspace ( { workspaceId } ) ;
9999 return response . result ! ;
100- } ) ) ;
100+ } ) , { signal } ) ;
101101 }
102102
103103 async startWorkspace ( workspaceId : string ) : Promise < Workspace > {
@@ -107,11 +107,11 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
107107 } ) ) ;
108108 }
109109
110- async getOwnerToken ( workspaceId : string ) : Promise < string > {
110+ async getOwnerToken ( workspaceId : string , signal ?: AbortSignal ) : Promise < string > {
111111 return this . _wrapError ( this . _workaroundGoAwayBug ( async ( ) => {
112112 const response = await this . workspaceService . getOwnerToken ( { workspaceId } ) ;
113113 return response . token ;
114- } ) ) ;
114+ } ) , { signal } ) ;
115115 }
116116
117117 async getSSHKeys ( ) : Promise < SSHKey [ ] > {
@@ -214,13 +214,14 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
214214 }
215215 }
216216
217- private async _wrapError < T > ( callback : ( ) => Promise < T > ) : Promise < T > {
218- const maxRetries = 5 ;
217+ private async _wrapError < T > ( callback : ( ) => Promise < T > , opts ?: { maxRetries ?: number ; signal ?: AbortSignal } ) : Promise < T > {
218+ const maxRetries = opts ?. maxRetries ?? 5 ;
219219 let retries = 0 ;
220220
221221 const onError : ( e : any ) => Promise < T > = async ( e ) => {
222222 const err = ConnectError . from ( e ) ;
223- if ( retries ++ < maxRetries && ( err . code === Code . Unavailable || err . code === Code . Aborted ) ) {
223+ const shouldRetry = opts ?. signal ? ! opts . signal . aborted : retries ++ < maxRetries ;
224+ if ( shouldRetry && ( err . code === Code . Unavailable || err . code === Code . Aborted ) ) {
224225 await timeout ( 1000 ) ;
225226 return callback ( ) . catch ( onError ) ;
226227 }
0 commit comments