MCPcopy Index your code
hub / github.com/coder/coder / waitForAgentCond

Function waitForAgentCond

cli/open.go:524–548  ·  view source on GitHub ↗

waitForAgentCond uses the watch workspace API to update the agent information until the condition is met.

(ctx context.Context, client *codersdk.Client, workspace codersdk.Workspace, workspaceAgent codersdk.WorkspaceAgent, cond func(codersdk.WorkspaceAgent) bool)

Source from the content-addressed store, hash-verified

522// waitForAgentCond uses the watch workspace API to update the agent information
523// until the condition is met.
524func waitForAgentCond(ctx context.Context, client *codersdk.Client, workspace codersdk.Workspace, workspaceAgent codersdk.WorkspaceAgent, cond func(codersdk.WorkspaceAgent) bool) (codersdk.Workspace, codersdk.WorkspaceAgent, error) {
525 ctx, cancel := context.WithCancel(ctx)
526 defer cancel()
527
528 if cond(workspaceAgent) {
529 return workspace, workspaceAgent, nil
530 }
531
532 wc, err := client.WatchWorkspace(ctx, workspace.ID)
533 if err != nil {
534 return workspace, workspaceAgent, xerrors.Errorf("watch workspace: %w", err)
535 }
536
537 for workspace = range wc {
538 workspaceAgent, _, err = getWorkspaceAgent(workspace, workspaceAgent.Name)
539 if err != nil {
540 return workspace, workspaceAgent, xerrors.Errorf("get workspace agent: %w", err)
541 }
542 if cond(workspaceAgent) {
543 return workspace, workspaceAgent, nil
544 }
545 }
546
547 return workspace, workspaceAgent, xerrors.New("watch workspace: unexpected closed channel")
548}
549
550// isWindowsAbsPath does a simplistic check for if the path is an absolute path
551// on Windows. Drive letter or preceding `\` is interpreted as absolute.

Callers 1

openVSCodeMethod · 0.85

Calls 4

WatchWorkspaceMethod · 0.80
getWorkspaceAgentFunction · 0.70
NewMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected