declare module "promises" { /** Module P: Generic Promises for TypeScript Project, documentation, and license: https://github.com/pragmatrix/Promise */ /** Returns a new "Deferred" value that may be resolved or rejected. */ export function defer(): Deferred; /** Converts a value to a resolved promise. */ export function resolve(v: Value): Promise; /** Returns a rejected promise. */ export function reject(err: Rejection): Promise; /** http://en.wikipedia.org/wiki/Anamorphism Given a seed value, unfold calls the unspool function, waits for the returned promise to be resolved, and then calls it again if a next seed value was returned. All the values of all promise results are collected into the resulting promise which is resolved as soon the last generated element value is resolved. */ export function unfold(unspool: (current: Seed) => { promise: Promise; next?: Seed; }, seed: Seed): Promise; /** The status of a Promise. Initially a Promise is Unfulfilled and may change to Rejected or Resolved. Once a promise is either Rejected or Resolved, it can not change its status anymore. */ export enum Status { Unfulfilled = 0, Rejected = 1, Resolved = 2, } /** If a promise gets rejected, at least a message that indicates the error or reason for the rejection must be provided. */ export interface Rejection { message: string; } /** Both Promise and Deferred share these properties. */ export interface PromiseState { status: Status; result?: Value; error?: Rejection; } /** A Promise supports basic composition and registration of handlers that are called when the promise is fulfilled. When multiple handlers are registered with done(), fail(), or always(), they are called in the same order. */ export interface Promise extends PromiseState { /** Returns a promise that represents a promise chain that consists of this promise and the promise that is returned by the function provided. The function receives the value of this promise as soon it is resolved. If this promise fails, the function is never called and the returned promise will also fail. */ then(f: (v: Value) => Promise): Promise; then(f: (v: Value) => T2): Promise; done(f: (v: Value) => void): Promise; fail(f: (err: Rejection) => void): Promise; always(f: (v?: Value, err?: Rejection) => void): Promise; } /** Deferred supports the explicit resolving and rejecting of the promise and the registration of fulfillment handlers. A Deferred should be only visible to the function that initially sets up an asynchronous process. Callers of that function should only see the Promise that is returned by promise(). */ export interface Deferred extends PromiseState { promise(): Promise; resolve(result?: Value): Deferred; reject(err: Rejection): Deferred; done(f: (v: Value) => void): Deferred; fail(f: (err: Rejection) => void): Deferred; always(f: (v?: Value, err?: Rejection) => void): Deferred; } /** Creates a promise that gets resolved when all the promises in the argument list get resolved. As soon one of the arguments gets rejected, the resulting promise gets rejected. If no promises were provided, the resulting promise is immediately resolved. */ export function when(...promises: Promise[]): Promise; /** Promise Generators and Iterators. */ export interface Generator { (): Iterator; } export interface Iterator { advance(): Promise; current: E; } export function generator(g: () => () => Promise): Generator; export function iterator(f: () => Promise): Iterator; /** Iterator functions. */ export function each(gen: Generator, f: (e: E) => void): Promise<{}>; /** std */ export function isUndefined(v: any): boolean; }