Clarify session helper

This commit is contained in:
JP Ungaretti 2022-04-14 17:10:11 -05:00
parent 322fae53b1
commit 4452f37819
5 changed files with 10 additions and 9 deletions

View file

@ -61,7 +61,8 @@ func (a *App) StopProgressIndicator() {
a.io.StopProgressIndicator()
}
func startSession(ctx context.Context, codespace *api.Codespace, a *App, debug bool, debugFile string) (*liveshare.Session, func(*error), error) {
// Connects to a codespace using Live Share and returns that session along with a function to end it
func startLiveShareSession(ctx context.Context, codespace *api.Codespace, a *App, debug bool, debugFile string) (*liveshare.Session, func(*error), error) {
// While connecting, ensure in the background that the user has keys installed.
// That lets us report a more useful error message if they don't.
authkeys := make(chan error, 1)

View file

@ -37,11 +37,11 @@ func (a *App) Jupyter(ctx context.Context, codespaceName string) error {
return err
}
session, closeSession, err := startSession(ctx, codespace, a, false, "")
session, endSession, err := startLiveShareSession(ctx, codespace, a, false, "")
if err != nil {
return err
}
defer closeSession(&err)
defer endSession(&err)
a.StartProgressIndicatorWithLabel("Starting JupyterLab on codespace")
serverPort, serverUrl, err := session.StartJupyterServer(ctx)

View file

@ -41,11 +41,11 @@ func (a *App) Logs(ctx context.Context, codespaceName string, follow bool) (err
return err
}
session, closeSession, err := startSession(ctx, codespace, a, false, "")
session, endSession, err := startLiveShareSession(ctx, codespace, a, false, "")
if err != nil {
return err
}
defer closeSession(&err)
defer endSession(&err)
// Ensure local port is listening before client (getPostCreateOutput) connects.
listen, err := net.Listen("tcp", "127.0.0.1:0") // arbitrary port

View file

@ -55,11 +55,11 @@ func (a *App) ListPorts(ctx context.Context, codespaceName string, exporter cmdu
devContainerCh := getDevContainer(ctx, a.apiClient, codespace)
session, closeSession, err := startSession(ctx, codespace, a, false, "")
session, endSession, err := startLiveShareSession(ctx, codespace, a, false, "")
if err != nil {
return err
}
defer closeSession(&err)
defer endSession(&err)
a.StartProgressIndicatorWithLabel("Fetching ports")
ports, err := session.GetSharedServers(ctx)

View file

@ -121,11 +121,11 @@ func (a *App) SSH(ctx context.Context, sshArgs []string, opts sshOptions) (err e
return err
}
session, closeSession, err := startSession(ctx, codespace, a, opts.debug, opts.debugFile)
session, endSession, err := startLiveShareSession(ctx, codespace, a, opts.debug, opts.debugFile)
if err != nil {
return err
}
defer closeSession(&err)
defer endSession(&err)
a.StartProgressIndicatorWithLabel("Fetching SSH Details")
remoteSSHServerPort, sshUser, err := session.StartSSHServer(ctx)