GetCodespaceConnection waits until a codespace is able to be connected to and initializes a connection to it.
(ctx context.Context, progress progressIndicator, apiClient apiClient, codespace *api.Codespace)
| 58 | // GetCodespaceConnection waits until a codespace is able |
| 59 | // to be connected to and initializes a connection to it. |
| 60 | func GetCodespaceConnection(ctx context.Context, progress progressIndicator, apiClient apiClient, codespace *api.Codespace) (*connection.CodespaceConnection, error) { |
| 61 | codespace, err := waitUntilCodespaceConnectionReady(ctx, progress, apiClient, codespace) |
| 62 | if err != nil { |
| 63 | return nil, err |
| 64 | } |
| 65 | |
| 66 | progress.StartProgressIndicatorWithLabel("Connecting to codespace") |
| 67 | defer progress.StopProgressIndicator() |
| 68 | |
| 69 | externalHttpClient, err := apiClient.ExternalHTTPClient() |
| 70 | if err != nil { |
| 71 | return nil, fmt.Errorf("error getting http client: %w", err) |
| 72 | } |
| 73 | |
| 74 | return connection.NewCodespaceConnection(ctx, codespace, externalHttpClient) |
| 75 | } |
| 76 | |
| 77 | // waitUntilCodespaceConnectionReady waits for a Codespace to be running and is able to be connected to. |
| 78 | func waitUntilCodespaceConnectionReady(ctx context.Context, progress progressIndicator, apiClient apiClient, codespace *api.Codespace) (*api.Codespace, error) { |
no test coverage detected