// A pool ping arrives before the new message is searchable: the thread search trails a write by tens of // seconds, so a refetch on the ping alone reads the thread as it was. The ping carries no thread id to // read by, so the desk reads again across that window; a newer ping restarts the schedule. export const POOL_PING_REREAD_MS = [5_000, 10_000, 15_000, 20_000, 25_000, 30_000, 45_000, 60_000]; export interface PoolPingReread { ping: () => void; cancel: () => void; } export const createPoolPingReread = (refresh: () => void, delays: number[] = POOL_PING_REREAD_MS): PoolPingReread => { let timers: ReturnType[] = []; const cancel = () => { timers.forEach(clearTimeout); timers = []; }; const ping = () => { cancel(); timers = delays.map((ms) => setTimeout(refresh, ms)); }; return { ping, cancel }; };