@studyportals/sp-hs-misc
Version:
Miscellaneous code used in HouseStark's projects
29 lines (28 loc) • 988 B
TypeScript
export type ObserverOfThrottleable<T = any> = (error: any, result: T) => void;
/**
* Aggregates an action whose execution can be deffered and offers the
* necessary functionality to notify observers when the action had been
* executed, providing the outcome.
*/
declare class Throttleable<T = any> {
private _actionFn;
private _observers;
private _result;
private _error;
private _executed;
protected get actionFn(): () => Promise<T>;
protected get observers(): ObserverOfThrottleable<T>[];
protected get result(): T;
protected get error(): any;
protected get executed(): boolean;
constructor(actionFn: () => Promise<T>);
execute(): Promise<void>;
observe(observerFn: ObserverOfThrottleable<T>): void;
createObservingPromise(): Promise<T>;
protected notifyObservers(): void;
private notifyObserver;
private addObserver;
private executeActionAndSetOutcome;
private setExecutedFlag;
}
export { Throttleable };