Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

467 B
Raw Blame
/**
 * Wraps an async producer so that concurrent calls share a single in-flight
 * promise. Each settle (resolve or reject) clears the shared promise, so a later call
 * starts a fresh fetch
 */
export function coalesce<T>(producer: () => Promise<T>): () => Promise<T> {
  let inFlight: Promise<T> | null = null;
  return () => {
    if (inFlight) return inFlight;
    inFlight = producer().finally(() => {
      inFlight = null;
    });
    return inFlight;
  };
}