UNPKG

observation-js

Version:

A fully-typed TypeScript client for the waarneming.nl API.

37 lines (36 loc) 1.11 kB
/** * @internal * The structure of a registered interceptor. */ export interface Interceptor<V> { onFulfilled: (value: V) => V | Promise<V>; onRejected?: (error: unknown) => unknown; } /** * @internal * Manages a collection of interceptors. */ export declare class InterceptorManager<V> { private handlers; /** * Adds a new interceptor to the manager. * * @param onFulfilled - The function to run when the promise is fulfilled. * @param onRejected - The function to run when the promise is rejected. * @returns An ID that can be used to remove the interceptor later. */ use(onFulfilled: (value: V) => V | Promise<V>, onRejected?: (error: unknown) => unknown): number; /** * Removes an interceptor from the manager by its ID. * * @param id - The ID of the interceptor to remove. */ eject(id: number): void; /** * Iterates over all registered interceptors. * * @param fn - The function to execute for each interceptor. * @internal */ forEach(fn: (interceptor: Interceptor<V>) => void): void; }