MCPcopy Index your code
hub / github.com/getsentry/XcodeBuildMCP / runStep

Function runStep

src/server/mcp-shutdown.ts:56–105  ·  view source on GitHub ↗
(
  name: string,
  timeoutMs: number,
  operation: () => Promise<T>,
)

Source from the content-addressed store, hash-verified

54}
55
56async function runStep<T>(
57 name: string,
58 timeoutMs: number,
59 operation: () => Promise<T>,
60): Promise<ShutdownStepOutcome<T>> {
61 const startedAt = Date.now();
62 let timeoutHandle: NodeJS.Timeout | null = null;
63
64 try {
65 const timeoutPromise = new Promise<RunStepRaceOutcome<T>>((resolve) => {
66 timeoutHandle = setTimeout(() => resolve({ kind: 'timed_out' }), timeoutMs);
67 timeoutHandle.unref?.();
68 });
69
70 const operationOutcome = operation()
71 .then((value): RunStepRaceOutcome<T> => ({ kind: 'value', value }))
72 .catch(
73 (error): RunStepRaceOutcome<T> => ({
74 kind: 'error',
75 error: toErrorMessage(error),
76 }),
77 );
78 const outcome = await Promise.race([operationOutcome, timeoutPromise]);
79
80 if (outcome.kind === 'timed_out') {
81 return {
82 status: 'timed_out',
83 durationMs: Date.now() - startedAt,
84 };
85 }
86
87 if (outcome.kind === 'error') {
88 return {
89 status: 'failed',
90 durationMs: Date.now() - startedAt,
91 error: outcome.error,
92 };
93 }
94
95 return {
96 status: 'completed',
97 durationMs: Date.now() - startedAt,
98 value: outcome.value,
99 };
100 } finally {
101 if (timeoutHandle) {
102 clearTimeout(timeoutHandle);
103 }
104 }
105}
106
107const FAILURE_REASONS: ReadonlySet<McpShutdownReason> = new Set([
108 'startup-failure',

Callers 2

closeServerWithTimeoutFunction · 0.85
runMcpShutdownFunction · 0.85

Calls 2

toErrorMessageFunction · 0.90
resolveFunction · 0.85

Tested by

no test coverage detected