import * as plugins from '../plugins.js';

// Create main app state instance
export const appState = new plugins.domtools.plugins.smartstate.Smartstate();

const backgroundRefreshesInFlight = new Set<string>();

export function runBackgroundRefresh(key: string, errorMessage: string, task: () => Promise<void>): void {
  if (backgroundRefreshesInFlight.has(key)) return;
  backgroundRefreshesInFlight.add(key);
  void task()
    .catch((error) => console.error(errorMessage, error))
    .finally(() => backgroundRefreshesInFlight.delete(key));
}

