mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 02:27:43 +00:00
Fixes #30517 Supersedes community PR #30518. Original contributor credit is preserved below. Co-authored-by: Wooseong Kim <innocarpe@gmail.com>
16 lines
452 B
TypeScript
16 lines
452 B
TypeScript
const SESSION_PREFERENCE_READ_TIMEOUT_MS = 5000
|
|
|
|
export async function settleSessionPreferenceRead<T>(read: Promise<T>): Promise<T | undefined> {
|
|
let timeout: ReturnType<typeof setTimeout> | undefined
|
|
try {
|
|
return await Promise.race([
|
|
read,
|
|
new Promise<undefined>((resolve) => {
|
|
timeout = setTimeout(() => resolve(undefined), SESSION_PREFERENCE_READ_TIMEOUT_MS)
|
|
})
|
|
])
|
|
} finally {
|
|
clearTimeout(timeout)
|
|
}
|
|
}
|