UNPKG

2.55 kBTypeScriptView Raw
1import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
2import { Scheduler } from './_internals/interfaces/Scheduler';
3export { Scheduler, SchedulerReportItem, SchedulerSequenceItem } from './_internals/interfaces/Scheduler';
4/**
5 * Constraints to be applied on {@link scheduler}
6 * @remarks Since 2.2.0
7 * @public
8 */
9export interface SchedulerConstraints {
10 /**
11 * Ensure that all scheduled tasks will be executed in the right context (for instance it can be the `act` of React)
12 * @remarks Since 1.21.0
13 */
14 act: (f: () => Promise<void>) => Promise<unknown>;
15}
16/**
17 * For scheduler of promises
18 * @remarks Since 1.20.0
19 * @public
20 */
21export declare function scheduler<TMetaData = unknown>(constraints?: SchedulerConstraints): Arbitrary<Scheduler<TMetaData>>;
22/**
23 * For custom scheduler with predefined resolution order
24 *
25 * Ordering is defined by using a template string like the one generated in case of failure of a {@link scheduler}
26 *
27 * It may be something like:
28 *
29 * @example
30 * ```typescript
31 * fc.schedulerFor()`
32 * -> [task\${2}] promise pending
33 * -> [task\${3}] promise pending
34 * -> [task\${1}] promise pending
35 * `
36 * ```
37 *
38 * Or more generally:
39 * ```typescript
40 * fc.schedulerFor()`
41 * This scheduler will resolve task ${2} first
42 * followed by ${3} and only then task ${1}
43 * `
44 * ```
45 *
46 * WARNING:
47 * Custom scheduler will
48 * neither check that all the referred promises have been scheduled
49 * nor that they resolved with the same status and value.
50 *
51 *
52 * WARNING:
53 * If one the promises is wrongly defined it will fail - for instance asking to resolve 5 while 5 does not exist.
54 *
55 * @remarks Since 1.25.0
56 * @public
57 */
58declare function schedulerFor<TMetaData = unknown>(constraints?: SchedulerConstraints): (_strs: TemplateStringsArray, ...ordering: number[]) => Scheduler<TMetaData>;
59/**
60 * For custom scheduler with predefined resolution order
61 *
62 * WARNING:
63 * Custom scheduler will not check that all the referred promises have been scheduled.
64 *
65 *
66 * WARNING:
67 * If one the promises is wrongly defined it will fail - for instance asking to resolve 5 while 5 does not exist.
68 *
69 * @param customOrdering - Array defining in which order the promises will be resolved.
70 * Id of the promises start at 1. 1 means first scheduled promise, 2 second scheduled promise and so on.
71 *
72 * @remarks Since 1.25.0
73 * @public
74 */
75declare function schedulerFor<TMetaData = unknown>(customOrdering: number[], constraints?: SchedulerConstraints): Scheduler<TMetaData>;
76export { schedulerFor };