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

Function ensureViewerIsPolling

examples/pdf-server/server.ts:264–276  ·  view source on GitHub ↗

* Wait for the viewer's first poll_pdf_commands call. * * Called before waitForPageData() / waitForSaveData() so a viewer that never * mounted fails in ~8s with a specific message instead of a generic 45s * "Timeout waiting for ..." that gives no hint why. * * Intentionally does NOT touch poll

(uuid: string)

Source from the content-addressed store, hash-verified

262 * can wait independently and all observe the same add() when it happens.
263 */
264async function ensureViewerIsPolling(uuid: string): Promise<void> {
265 const deadline = Date.now() + VIEWER_FIRST_POLL_GRACE_MS;
266 while (!viewsPolled.has(uuid)) {
267 if (Date.now() >= deadline) {
268 throw new Error(
269 `Viewer never connected for viewUUID ${uuid} (no poll within ${VIEWER_FIRST_POLL_GRACE_MS / 1000}s). ` +
270 `The iframe likely failed to mount — this happens when the conversation ` +
271 `goes idle before the viewer finishes loading. Call display_pdf again to get a fresh viewUUID.`,
272 );
273 }
274 await new Promise((r) => setTimeout(r, 100));
275 }
276}
277
278// =============================================================================
279// Pending save_as Requests (request-response bridge via client)

Callers 1

processInteractCommandFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…