MCPcopy
hub / github.com/codeaashu/claude-code / waitForTaskCompletion

Function waitForTaskCompletion

src/tools/TaskOutputTool/TaskOutputTool.tsx:118–143  ·  view source on GitHub ↗
(taskId: string, getAppState: () => {
  tasks?: Record<string, TaskState>;
}, timeoutMs: number, abortController?: AbortController)

Source from the content-addressed store, hash-verified

116
117// Wait for task to complete
118async function waitForTaskCompletion(taskId: string, getAppState: () => {
119 tasks?: Record<string, TaskState>;
120}, timeoutMs: number, abortController?: AbortController): Promise<TaskState | null> {
121 const startTime = Date.now();
122 while (Date.now() - startTime < timeoutMs) {
123 // Check abort signal
124 if (abortController?.signal.aborted) {
125 throw new AbortError();
126 }
127 const state = getAppState();
128 const task = state.tasks?.[taskId] as TaskState | undefined;
129 if (!task) {
130 return null;
131 }
132 if (task.status !== 'running' && task.status !== 'pending') {
133 return task;
134 }
135
136 // Wait before polling again
137 await sleep(100);
138 }
139
140 // Timeout - return current state
141 const finalState = getAppState();
142 return finalState.tasks?.[taskId] as TaskState ?? null;
143}
144export const TaskOutputTool: Tool<InputSchema, TaskOutputToolOutput> = buildTool({
145 name: TASK_OUTPUT_TOOL_NAME,
146 searchHint: 'read output/logs from a background task',

Callers 1

callFunction · 0.85

Calls 2

getAppStateFunction · 0.50
sleepFunction · 0.50

Tested by

no test coverage detected