diff --git a/tspromise/tspromise-test.ts b/tspromise/tspromise-test.ts new file mode 100644 index 000000000..79903f0ce --- /dev/null +++ b/tspromise/tspromise-test.ts @@ -0,0 +1,21 @@ +/// + +import Promise = require('tspromise'); + +var MyFuncFunc = Promise.async((a: boolean, b: number) => { + console.log('[a] ' + a); + yield(Promise.waitAsync(1000)); + console.log('[b]' + b); +}); + +MyFuncFunc(true, 10); + +Promise.all([Promise.waitAsync(10), Promise.waitAsync(20)]).then(() => { + return new Promise((resolve, reject) => { + resolve('test'); + }); +}).then(() => { + throw (new Error()); +}).catch((e) => { + console.log(e.message); +}); \ No newline at end of file diff --git a/tspromise/tspromise.d.ts b/tspromise/tspromise.d.ts new file mode 100644 index 000000000..8608d105c --- /dev/null +++ b/tspromise/tspromise.d.ts @@ -0,0 +1,35 @@ +/// +declare class Thenable { + then(onFulfilled: (value: T) => Thenable, onRejected?: (error: Error) => TR): Thenable; + then(onFulfilled: (value: T) => Thenable, onRejected?: (error: Error) => void): Thenable; + then(onFulfilled: (value: T) => TR, onRejected?: (error: Error) => void): Thenable; + then(onFulfilled: (value: T) => TR, onRejected?: (error: Error) => TR): Thenable; + catch(onRejected: (error: Error) => T): Thenable; +} + +interface NodeCallback { + (err: Error, value: T): void; +} + +declare module "tspromise" { + class Promise extends Thenable { + constructor(callback: (resolve: (value?: T) => void, reject?: (error: Error) => void) => void); + static resolve(value?: T): Thenable; + static resolve(promise: Thenable): Thenable; + static reject(error: Error): Thenable; + static all(promises: Thenable[]): Thenable; + static async(callback: () => TR): () => Thenable; + static async(callback: (p1: T1) => TR): (p1: T1) => Thenable; + static async(callback: (p1: T1, p2: T2) => TR): (p1: T1, p2: T2) => Thenable; + static async(callback: (p1: T1, p2: T2, p3: T3) => TR): (p1: T1, p2: T2, p3: T3) => Thenable; + static async(callback: (p1: T1, p2: T2, p3: T3, p4: T4) => TR): (p1: T1, p2: T2, p3: T3, p4: T4) => Thenable; + static spawn(generatorFunction: () => TR): Thenable; + static rewriteFolderSync(path: string): void; + static waitAsync(time: number): Thenable<{}>; + static nfcall(obj: any, methodName: String, ...args: any[]): Thenable; + } + + export = Promise; +} + +declare function yield(promise: Thenable): T;