@@ -33,9 +33,9 @@ function isTelemetryEnabled(): boolean {
33
33
}
34
34
35
35
export interface IGitpodAPI {
36
- getWorkspace ( workspaceId : string ) : Promise < Workspace > ;
36
+ getWorkspace ( workspaceId : string , signal ?: AbortSignal ) : Promise < Workspace > ;
37
37
startWorkspace ( workspaceId : string ) : Promise < Workspace > ;
38
- getOwnerToken ( workspaceId : string ) : Promise < string > ;
38
+ getOwnerToken ( workspaceId : string , signal ?: AbortSignal ) : Promise < string > ;
39
39
getSSHKeys ( ) : Promise < SSHKey [ ] > ;
40
40
sendHeartbeat ( workspaceId : string ) : Promise < void > ;
41
41
sendDidClose ( workspaceId : string ) : Promise < void > ;
@@ -93,11 +93,11 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
93
93
}
94
94
95
95
96
- async getWorkspace ( workspaceId : string ) : Promise < Workspace > {
96
+ async getWorkspace ( workspaceId : string , signal ?: AbortSignal ) : Promise < Workspace > {
97
97
return this . _wrapError ( this . _workaroundGoAwayBug ( async ( ) => {
98
98
const response = await this . workspaceService . getWorkspace ( { workspaceId } ) ;
99
99
return response . result ! ;
100
- } ) ) ;
100
+ } ) , { signal } ) ;
101
101
}
102
102
103
103
async startWorkspace ( workspaceId : string ) : Promise < Workspace > {
@@ -107,11 +107,11 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
107
107
} ) ) ;
108
108
}
109
109
110
- async getOwnerToken ( workspaceId : string ) : Promise < string > {
110
+ async getOwnerToken ( workspaceId : string , signal ?: AbortSignal ) : Promise < string > {
111
111
return this . _wrapError ( this . _workaroundGoAwayBug ( async ( ) => {
112
112
const response = await this . workspaceService . getOwnerToken ( { workspaceId } ) ;
113
113
return response . token ;
114
- } ) ) ;
114
+ } ) , { signal } ) ;
115
115
}
116
116
117
117
async getSSHKeys ( ) : Promise < SSHKey [ ] > {
@@ -214,13 +214,14 @@ export class GitpodPublicApi extends Disposable implements IGitpodAPI {
214
214
}
215
215
}
216
216
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 ;
219
219
let retries = 0 ;
220
220
221
221
const onError : ( e : any ) => Promise < T > = async ( e ) => {
222
222
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 ) ) {
224
225
await timeout ( 1000 ) ;
225
226
return callback ( ) . catch ( onError ) ;
226
227
}
0 commit comments