/** * Creates a throttled publish function that coalesces rapid message bursts. * * Useful for scenarios with frequent rapid state changes (e.g., real-time collaboration, * live cursors). Instead of sending individual messages immediately, batches them * into a single broadcast after a throttle window. * * @param publish - Publish function from router (e.g., `router.publish`) * @param windowMs - Throttle window in milliseconds (default: 50ms) * @returns Function that queues messages for throttled publishing * * @example * ```typescript * import { createRouter } from "@ws-kit/zod"; * * const router = createRouter(); * const throttledPublish = createThrottledPublish( * router.publish.bind(router), * 50 // ms * ); * * // Fast state changes * throttledPublish("room", { cursor: { x: 10, y: 20 } }); * throttledPublish("room", { cursor: { x: 11, y: 21 } }); * throttledPublish("room", { cursor: { x: 12, y: 22 } }); * * // Only one publish after 50ms window with the last message * ``` */ export declare function createThrottledPublish(publish: (channel: string, message: unknown) => Promise, windowMs?: number): (channel: string, message: unknown) => void; /** * Configuration for throttled broadcast behavior. */ export interface ThrottledBroadcastConfig { /** * Throttle window in milliseconds. Rapid messages within this window * are coalesced into a single broadcast. * * @default 50 */ windowMs?: number; /** * Optional callback when messages are flushed. * Useful for logging, metrics, or debugging. */ onFlush?: (channel: string, messageCount: number) => void; } /** * Advanced version with batching and flushing callbacks. * * @param publish - Publish function from router * @param config - Configuration options * @returns Function that queues messages for throttled publishing * * @example * ```typescript * const throttledPublish = createAdvancedThrottledPublish( * router.publish.bind(router), * { * windowMs: 50, * onFlush: (channel, count) => { * console.log(`Flushed ${count} messages to ${channel}`); * }, * } * ); * ``` */ export declare function createAdvancedThrottledPublish(publish: (channel: string, message: unknown) => Promise, config?: ThrottledBroadcastConfig): (channel: string, message: unknown) => void; //# sourceMappingURL=throttle.d.ts.map