MCPcopy Index your code
hub / github.com/devcontainers/cli / startEventSeen

Function startEventSeen

src/spec-node/utils.ts:173–214  ·  view source on GitHub ↗
(params: DockerResolverParameters, labels: Record<string, string>, canceled: Promise<void>, output: Log, trace: boolean)

Source from the content-addressed store, hash-verified

171}
172
173export async function startEventSeen(params: DockerResolverParameters, labels: Record<string, string>, canceled: Promise<void>, output: Log, trace: boolean) {
174 if (params.cliVariant === CLIVariant.Wslc) {
175 return startEventSeenPolling(params, labels, canceled, output, trace);
176 }
177 const eventsProcess = await getEvents(params, { event: ['start'] });
178 return {
179 started: new Promise<void>((resolve, reject) => {
180 canceled.catch(err => {
181 eventsProcess.terminate();
182 reject(err);
183 });
184 const decoder = new StringDecoder('utf8');
185 let startPart = '';
186 eventsProcess.stdout.on('data', async chunk => {
187 if (chunk) {
188 const part = decoder.write(chunk);
189 if (trace) {
190 output.write(`Log: startEventSeen#data ${part.trim().replace(/\r?\n/g, '\r\n')}\r\n`);
191 }
192 const lines = (startPart + part).split('\n');
193 startPart = lines.pop()!;
194 for (const line of lines) {
195 if (line.trim()) {
196 try {
197 const info = JSON.parse(line);
198 // Docker uses 'status', Podman 'Status'. Docker v29.0.0 onwards use 'Action' as 'status' is deprecated.
199 if ((info.status || info.Status || info.Action) === 'start' && await hasLabels(params, info, labels)) {
200 eventsProcess.terminate();
201 resolve();
202 }
203 } catch (e) {
204 // Ignore invalid JSON.
205 console.error(e);
206 console.error(line);
207 }
208 }
209 }
210 }
211 });
212 })
213 };
214}
215
216// Polling-based fallback for runtimes that don't support `events` (e.g., wslc).
217function startEventSeenPolling(params: DockerResolverParameters, labels: Record<string, string>, canceled: Promise<void>, output: Log, trace: boolean) {

Callers 2

startContainerFunction · 0.90
spawnDevContainerFunction · 0.90

Calls 7

getEventsFunction · 0.90
startEventSeenPollingFunction · 0.85
hasLabelsFunction · 0.85
resolveFunction · 0.85
onMethod · 0.80
terminateMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected