UNPKG

1.15 kBTypeScriptView Raw
1/**
2 * Action that can be recorded for later execution against a Flushable
3 * in its flush() function.
4 */
5export declare type ScriptAction<T, R> = (t: T) => Promise<R>;
6/**
7 * Interface implemented by objects that can accumulate changes
8 * that require flushing.
9 */
10export interface Flushable {
11 /**
12 * Are there pending changes that need to be flushed?
13 */
14 dirty: boolean;
15 /**
16 * Flush any pending changes.
17 */
18 flush(): Promise<this>;
19}
20/**
21 * Interface to be implemented by Flushable objects that can accumulate a change script
22 * and play it synchronously.
23 */
24export interface ScriptedFlushable<T> extends Flushable {
25 /**
26 * Record an arbitrary action against the backing object.
27 * @param {(p: ProjectAsync) => Promise<any>} action
28 */
29 recordAction(action: ScriptAction<T, any>): this;
30}
31/**
32 * Defer the given action until the relevant ScriptableFlushable is flushable
33 * @param {ScriptedFlushable<T>} flushable
34 * @param {ScriptAction<T, R>} promise
35 */
36export declare function defer<T, R>(flushable: ScriptedFlushable<T>, promise: Promise<R>): void;
37//# sourceMappingURL=Flushable.d.ts.map
\No newline at end of file