From c16618cc4304b83e840ac3b7fa89be2d0771c3f8 Mon Sep 17 00:00:00 2001 From: soywiz Date: Wed, 23 Apr 2014 14:24:16 +0200 Subject: [PATCH 1/2] - Added tspromise definition --- tspromise/tspromise-test.ts | 21 +++++++++++++++++++++ tspromise/tspromise.d.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tspromise/tspromise-test.ts create mode 100644 tspromise/tspromise.d.ts 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; From 6550e264a59748eb7027a417b05390d693e2aebe Mon Sep 17 00:00:00 2001 From: soywiz Date: Wed, 23 Apr 2014 14:26:24 +0200 Subject: [PATCH 2/2] - Added info to definition --- tspromise/tspromise.d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tspromise/tspromise.d.ts b/tspromise/tspromise.d.ts index 8608d105c..0d1132ed1 100644 --- a/tspromise/tspromise.d.ts +++ b/tspromise/tspromise.d.ts @@ -1,4 +1,9 @@ -/// +// Type definitions for tspromise 0.0.4 +// Project: https://github.com/soywiz/tspromise +// Definitions by: Carlos Ballesteros Velasco +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// declare class Thenable { then(onFulfilled: (value: T) => Thenable, onRejected?: (error: Error) => TR): Thenable; then(onFulfilled: (value: T) => Thenable, onRejected?: (error: Error) => void): Thenable;