- Added tspromise definition

This commit is contained in:
soywiz
2014-04-23 14:24:16 +02:00
parent ae68eb5d41
commit c16618cc43
2 changed files with 56 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
/// <reference path="tspromise.d.ts" />
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<String>((resolve, reject) => {
resolve('test');
});
}).then(() => {
throw (new Error());
}).catch((e) => {
console.log(e.message);
});
+35
View File
@@ -0,0 +1,35 @@
/// <reference path="../node/node.d.ts" />
declare class Thenable<T> {
then<TR>(onFulfilled: (value: T) => Thenable<TR>, onRejected?: (error: Error) => TR): Thenable<TR>;
then<TR>(onFulfilled: (value: T) => Thenable<TR>, onRejected?: (error: Error) => void): Thenable<TR>;
then<TR>(onFulfilled: (value: T) => TR, onRejected?: (error: Error) => void): Thenable<TR>;
then<TR>(onFulfilled: (value: T) => TR, onRejected?: (error: Error) => TR): Thenable<TR>;
catch(onRejected: (error: Error) => T): Thenable<T>;
}
interface NodeCallback<T> {
(err: Error, value: T): void;
}
declare module "tspromise" {
class Promise<T> extends Thenable<T> {
constructor(callback: (resolve: (value?: T) => void, reject?: (error: Error) => void) => void);
static resolve<T>(value?: T): Thenable<T>;
static resolve<T>(promise: Thenable<T>): Thenable<T>;
static reject<T>(error: Error): Thenable<T>;
static all(promises: Thenable<any>[]): Thenable<any[]>;
static async<TR>(callback: () => TR): () => Thenable<TR>;
static async<T1, TR>(callback: (p1: T1) => TR): (p1: T1) => Thenable<TR>;
static async<T1, T2, TR>(callback: (p1: T1, p2: T2) => TR): (p1: T1, p2: T2) => Thenable<TR>;
static async<T1, T2, T3, TR>(callback: (p1: T1, p2: T2, p3: T3) => TR): (p1: T1, p2: T2, p3: T3) => Thenable<TR>;
static async<T1, T2, T3, T4, TR>(callback: (p1: T1, p2: T2, p3: T3, p4: T4) => TR): (p1: T1, p2: T2, p3: T3, p4: T4) => Thenable<TR>;
static spawn<TR>(generatorFunction: () => TR): Thenable<TR>;
static rewriteFolderSync(path: string): void;
static waitAsync(time: number): Thenable<{}>;
static nfcall<T>(obj: any, methodName: String, ...args: any[]): Thenable<T>;
}
export = Promise;
}
declare function yield<T>(promise: Thenable<T>): T;