HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/AppData/Roaming/npm/node_modules/command-code/node_modules/ai/src/util/notify.ts
import { asArray } from './as-array';

/**
 * A callback function that can be used to notify listeners.
 */
export type Listener<EVENT> = (event: EVENT) => PromiseLike<void> | void;

/**
 * Notifies all provided callbacks with the given event.
 * Errors in callbacks do not break the generation flow.
 */
export async function notify<EVENT>(options: {
  event: EVENT;
  callbacks?: Listener<EVENT> | Array<Listener<EVENT> | undefined | null>;
}): Promise<void> {
  for (const callback of asArray(options.callbacks)) {
    if (callback == null) continue;
    try {
      await callback(options.event);
    } catch (_ignored) {}
  }
}