RefreshContainers triggers an immediate update of the container list and waits for it to complete.
(ctx context.Context)
| 1160 | // RefreshContainers triggers an immediate update of the container list |
| 1161 | // and waits for it to complete. |
| 1162 | func (api *API) RefreshContainers(ctx context.Context) (err error) { |
| 1163 | defer func() { |
| 1164 | if err != nil { |
| 1165 | err = xerrors.Errorf("refresh containers failed: %w", err) |
| 1166 | } |
| 1167 | }() |
| 1168 | |
| 1169 | done := make(chan error, 1) |
| 1170 | var sent bool |
| 1171 | defer func() { |
| 1172 | if !sent { |
| 1173 | close(done) |
| 1174 | } |
| 1175 | }() |
| 1176 | select { |
| 1177 | case <-api.ctx.Done(): |
| 1178 | return xerrors.Errorf("API closed: %w", api.ctx.Err()) |
| 1179 | case <-ctx.Done(): |
| 1180 | return ctx.Err() |
| 1181 | case api.updateTrigger <- done: |
| 1182 | sent = true |
| 1183 | select { |
| 1184 | case <-api.ctx.Done(): |
| 1185 | return xerrors.Errorf("API closed: %w", api.ctx.Err()) |
| 1186 | case <-ctx.Done(): |
| 1187 | return ctx.Err() |
| 1188 | case err := <-done: |
| 1189 | return err |
| 1190 | } |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | func (api *API) getContainers() (codersdk.WorkspaceAgentListContainersResponse, error) { |
| 1195 | api.mu.RLock() |