mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-25 11:11:46 +08:00
- Added tspromise definition
This commit is contained in:
@@ -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);
|
||||
});
|
||||
Vendored
+35
@@ -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;
|
||||
Reference in New Issue
Block a user