import { Arbitrary } from './definition/Arbitrary'; /** * Define an item to be passed to `scheduleSequence` * @public */ export declare type SchedulerSequenceItem = { builder: () => Promise; label: string; metadata?: TMetaData; } | (() => Promise); /** * Describe a task for the report produced by the scheduler * @public */ export interface SchedulerReportItem { /** * Execution status for this task * - resolved: task released by the scheduler and successful * - rejected: task released by the scheduler but with errors * - pending: task still pending in the scheduler, not released yet */ status: 'resolved' | 'rejected' | 'pending'; /** * How was this task scheduled? * - promise: schedule * - function: scheduleFunction * - sequence: scheduleSequence */ schedulingType: 'promise' | 'function' | 'sequence'; /** Incremental id for the task, first received task has taskId = 1 */ taskId: number; /** Label of the task */ label: string; /** Metadata linked when scheduling the task */ metadata?: TMetaData; /** Stringified version of the output or error computed using fc.stringify */ outputValue?: string; } /** * Constraints to be applied on {@link scheduler} * @public */ export interface SchedulerConstraints { /** Ensure that all scheduled tasks will be executed in the right context (for instance it can be the `act` of React) */ act: (f: () => Promise) => Promise; } /** * Instance able to reschedule the ordering of promises * for a given app * @public */ export interface Scheduler { /** Wrap a new task using the Scheduler */ schedule: (task: Promise, label?: string, metadata?: TMetaData) => Promise; /** Automatically wrap function output using the Scheduler */ scheduleFunction: (asyncFunction: (...args: TArgs) => Promise) => (...args: TArgs) => Promise; /** * Schedule a sequence of Promise to be executed sequencially. * Items within the sequence might be interleaved by other scheduled operations. * * Please note that whenever an item from the sequence has started, * the scheduler will wait until its end before moving to another scheduled task. * * A handle is returned by the function in order to monitor the state of the sequence. * Sequence will be marked: * - done if all the promises have been executed properly * - faulty if one of the promises within the sequence throws */ scheduleSequence(sequenceBuilders: SchedulerSequenceItem[]): { done: boolean; faulty: boolean; task: Promise<{ done: boolean; faulty: boolean; }>; }; /** * Count of pending scheduled tasks */ count(): number; /** * Wait one scheduled task to be executed * @throws Whenever there is no task scheduled */ waitOne: () => Promise; /** * Wait all scheduled tasks, * including the ones that might be created by one of the resolved task */ waitAll: () => Promise; /** * Produce an array containing all the scheduled tasks so far with their execution status. * If the task has been executed, it includes a string representation of the associated output or error produced by the task if any. * * Tasks will be returned in the order they get executed by the scheduler. */ report: () => SchedulerReportItem[]; } /** * For scheduler of promises * @public */ declare function scheduler(constraints?: SchedulerConstraints): Arbitrary>; /** * For custom scheduler with predefined resolution order * * Ordering is defined by using a template string like the one generated in case of failure of a {@link scheduler} * * It may be something like: * * @example * ```typescript * fc.schedulerFor()` * -> [task\${2}] promise pending * -> [task\${3}] promise pending * -> [task\${1}] promise pending * ` * ``` * * Or more generally: * ```typescript * fc.schedulerFor()` * This scheduler will resolve task ${2} first * followed by ${3} and only then task ${1} * ` * ``` * * WARNING: * Custom scheduler will * neither check that all the referred promises have been scheduled * nor that they resolved with the same status and value. * * * WARNING: * If one the promises is wrongly defined it will fail - for instance asking to resolve 5 while 5 does not exist. * * @public */ declare function schedulerFor(constraints?: SchedulerConstraints): (_strs: TemplateStringsArray, ...ordering: number[]) => Scheduler; /** * For custom scheduler with predefined resolution order * * WARNING: * Custom scheduler will not check that all the referred promises have been scheduled. * * * WARNING: * If one the promises is wrongly defined it will fail - for instance asking to resolve 5 while 5 does not exist. * * @param customOrdering - Array defining in which order the promises will be resolved. * Id of the promises start at 1. 1 means first scheduled promise, 2 second scheduled promise and so on. * * @public */ declare function schedulerFor(customOrdering: number[], constraints?: SchedulerConstraints): Scheduler; export { scheduler, schedulerFor };