export declare type FulfilledHandler = ((result: T) => R | PersistencePromise) | null; export declare type RejectedHandler = ((reason: Error) => R | PersistencePromise) | null; export declare type Resolver = (value?: T) => void; export declare type Rejector = (error: Error) => void; /** * PersistencePromise<> is essentially a re-implementation of Promise<> except * it has a .next() method instead of .then() and .next() and .catch() callbacks * are executed synchronously when a PersistencePromise resolves rather than * asynchronously (Promise<> implementations use setImmediate() or similar). * * This is necessary to interoperate with IndexedDB which will automatically * commit transactions if control is returned to the event loop without * synchronously initiating another operation on the transaction. * * NOTE: .then() and .catch() only allow a single consumer, unlike normal * Promises. */ export declare class PersistencePromise { private nextCallback; private catchCallback; private result; private error; private isDone; private callbackAttached; constructor(callback: (resolve: Resolver, reject: Rejector) => void); catch(fn: (error: Error) => R | PersistencePromise): PersistencePromise; next(nextFn?: FulfilledHandler, catchFn?: RejectedHandler): PersistencePromise; toPromise(): Promise; private wrapUserFunction(fn); private wrapSuccess(nextFn, value); private wrapFailure(catchFn, error); static resolve(): PersistencePromise; static resolve(result: R): PersistencePromise; static reject(error: Error): PersistencePromise; static waitFor(all: { forEach: (cb: ((el: PersistencePromise) => void)) => void; }): PersistencePromise; /** * Given an array of predicate functions that asynchronously evaluate to a * boolean, implements a short-circuiting `or` between the results. Predicates * will be evaluated until one of them returns `true`, then stop. The final * result will be whether any of them returned `true`. */ static or(predicates: Array<() => PersistencePromise>): PersistencePromise; /** * Given an iterable, call the given function on each element in the * collection and wait for all of the resulting concurrent PersistencePromises * to resolve. */ static forEach(collection: { forEach: ((cb: ((r: R, s?: S) => void)) => void); }, f: ((r: R, s: S) => PersistencePromise) | ((r: R) => PersistencePromise)): PersistencePromise; }