MCPcopy Create free account
hub / github.com/modelcontextprotocol/ext-apps / waitForSaveData

Function waitForSaveData

examples/pdf-server/server.ts:292–311  ·  view source on GitHub ↗

* Wait for the viewer to build annotated PDF bytes and submit them as base64. * Rejects on timeout, abort, or when the viewer reports an error.

(
  requestId: string,
  signal?: AbortSignal,
)

Source from the content-addressed store, hash-verified

290 * Rejects on timeout, abort, or when the viewer reports an error.
291 */
292function waitForSaveData(
293 requestId: string,
294 signal?: AbortSignal,
295): Promise<string> {
296 return new Promise<string>((resolve, reject) => {
297 const settle = (v: string | Error) => {
298 clearTimeout(timer);
299 signal?.removeEventListener("abort", onAbort);
300 pendingSaveRequests.delete(requestId);
301 v instanceof Error ? reject(v) : resolve(v);
302 };
303 const onAbort = () => settle(new Error("interact request cancelled"));
304 const timer = setTimeout(
305 () => settle(new Error("Timeout waiting for PDF bytes from viewer")),
306 GET_PAGES_TIMEOUT_MS,
307 );
308 signal?.addEventListener("abort", onAbort);
309 pendingSaveRequests.set(requestId, settle);
310 });
311}
312
313const pendingStateRequests = new Map<string, (v: string | Error) => void>();
314

Callers 1

processInteractCommandFunction · 0.85

Calls 2

settleFunction · 0.85
addEventListenerMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…