UNPKG

@traxjs/trax

Version:

Reactive state management

15 lines (14 loc) 1.09 kB
import { ProcessingContext } from "./types"; type SyncFunction = (...args: any[]) => any; type AsyncGenFunction = (...args: any[]) => Generator<Promise<any>, void, any>; /** * Wrap sync and generator-based async functions to produce an event stream processing context * @param fn the function to wrap * @param startProcessingContext a function that should start and return the processing context * @param error a function that will be called when errors must be raised * @param onProcessStart [optional] a callback called a the beginning of each processing step. Will stop the processing if it return false * @param onProcessEnd [optional] a callback called at the end of each processing step * @returns */ export declare function wrapFunction<F extends SyncFunction | AsyncGenFunction>(fn: F, startProcessingContext: () => ProcessingContext, error: (msg: any) => void, onProcessStart?: () => false | void, onProcessEnd?: (done: boolean) => void): ReturnType<F> extends Generator ? (...args: Parameters<F>) => Promise<any> : (...args: Parameters<F>) => ReturnType<F>; export {};