@@ -51,11 +51,10 @@ export class Remote {
5151 * Try to get the workspace running. Return undefined if the user canceled.
5252 */
5353 private async maybeWaitForRunning (
54+ restClient : Api ,
5455 workspace : Workspace ,
5556 label : string ,
5657 binPath : string ,
57- baseUrlRaw : string ,
58- token : string ,
5958 ) : Promise < Workspace | undefined > {
6059 const workspaceName = `${ workspace . owner_name } /${ workspace . name } `
6160
@@ -95,7 +94,6 @@ export class Remote {
9594 title : "Waiting for workspace build..." ,
9695 } ,
9796 async ( ) => {
98- let restClient = await makeCoderSdk ( baseUrlRaw , token , this . storage )
9997 const globalConfigDir = path . dirname ( this . storage . getSessionTokenPath ( label ) )
10098 while ( workspace . latest_build . status !== "running" ) {
10199 ++ attempts
@@ -111,9 +109,6 @@ export class Remote {
111109 if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
112110 return undefined
113111 }
114- // Recreate REST client since confirmStart may have waited an
115- // indeterminate amount of time for confirmation.
116- restClient = await makeCoderSdk ( baseUrlRaw , token , this . storage )
117112 writeEmitter = initWriteEmitterAndTerminal ( )
118113 this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
119114 workspace = await startWorkspaceIfStoppedOrFailed (
@@ -131,9 +126,6 @@ export class Remote {
131126 if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
132127 return undefined
133128 }
134- // Recreate REST client since confirmStart may have waited an
135- // indeterminate amount of time for confirmation.
136- restClient = await makeCoderSdk ( baseUrlRaw , token , this . storage )
137129 writeEmitter = initWriteEmitterAndTerminal ( )
138130 this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
139131 workspace = await startWorkspaceIfStoppedOrFailed (
@@ -324,16 +316,13 @@ export class Remote {
324316
325317 // If the workspace is not in a running state, try to get it running.
326318 if ( workspace . latest_build . status !== "running" ) {
327- if ( ! ( await this . maybeWaitForRunning ( workspace , parts . label , binaryPath , baseUrlRaw , token ) ) ) {
319+ const updatedWorkspace = await this . maybeWaitForRunning ( workspaceRestClient , workspace , parts . label , binaryPath )
320+ if ( ! updatedWorkspace ) {
328321 // User declined to start the workspace.
329322 await this . closeRemote ( )
330- } else {
331- // Start over with a fresh REST client because we may have waited an
332- // indeterminate amount amount of time for confirmation to start the
333- // workspace.
334- await this . setup ( remoteAuthority )
323+ return
335324 }
336- return
325+ workspace = updatedWorkspace
337326 }
338327 this . commands . workspace = workspace
339328
0 commit comments