import type { Socket } from "atom.io/realtime" import { getSubMap } from "./create-subscriber.ts" /** * Observe the current cleanup wave for a socket's pending subscriptions. * * @remarks * This is exported for internal framework coordination, especially test * teardown, and is not intended as a general-purpose public utility. */ export async function observeSocketWindDown(socket: Socket): Promise { const pendingSubscriptions = [...getSubMap(socket)].flatMap(([key, sub]) => sub.refcount === 0 && sub.completion !== null ? [[key, sub.completion] as const] : [], ) await Promise.all(pendingSubscriptions.map(([, timer]) => timer)) return pendingSubscriptions.map(([key]) => key) }