({
api,
sessionId,
pollIntervalMs = DEFAULT_POLL_INTERVAL_MS,
timeoutMs = DEFAULT_TIMEOUT_MS,
})
| 74 | * @returns {Promise<{status: string, [key: string]: any}>} the session, once ready |
| 75 | */ |
| 76 | export async function ensureSessionAwake({ |
| 77 | api, |
| 78 | sessionId, |
| 79 | pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, |
| 80 | timeoutMs = DEFAULT_TIMEOUT_MS, |
| 81 | }) { |
| 82 | const deadline = AbortSignal.timeout(timeoutMs); |
| 83 | try { |
| 84 | return await waitUntilReady(api, sessionId, pollIntervalMs, deadline); |
| 85 | } catch (error) { |
| 86 | if (deadline.aborted) { |
| 87 | throw new Error( |
| 88 | `Timed out waiting for session ${sessionId} to become ready.`, |
| 89 | { cause: error }, |
| 90 | ); |
| 91 | } |
| 92 | throw error; |
| 93 | } |
| 94 | } |
no test coverage detected