Adding denodeify definition for Q

This commit is contained in:
Michel Salib
2014-06-10 16:43:12 +02:00
parent e713407390
commit 48a2c18384
2 changed files with 6 additions and 3 deletions

View File

@@ -26,7 +26,7 @@ Q.delay("asdf", 1000).then(x => x.length);
var eventualAdd = Q.promised((a?: number, b?: number) => a + b);
eventualAdd(Q(1), Q(2)).then(x => x.toExponential());
var eventually = function (eventually) {
var eventually = function (eventually: any) {
return Q.delay(eventually, 1000);
};
@@ -38,7 +38,7 @@ Q.when(x, function (x) {
Q.all([
eventually(10),
eventually(20)
]).spread(function (x, y) {
]).spread(function (x: any, y: any) {
console.log(x, y);
});
@@ -97,7 +97,7 @@ Q.when(Q(8), num => num + "!").then(str => str.split(','));
declare function saveToDisk(): Q.Promise<any>;
declare function saveToCloud(): Q.Promise<any>;
Q.allSettled([saveToDisk(), saveToCloud()]).spread(function (disk, cloud) {
Q.allSettled([saveToDisk(), saveToCloud()]).spread(function (disk: any, cloud: any) {
console.log("saved to disk:", disk.state === "fulfilled");
console.log("saved to cloud:", cloud.state === "fulfilled");
@@ -115,3 +115,5 @@ var nodeStyle = (input: string, cb: Function) => {
Q.nfapply(nodeStyle, ["foo"]).done((result: string) => {});
Q.nfcall(nodeStyle, "foo").done((result: string) => {});
Q.denodeify(nodeStyle)('foo').done((result: string) => {});
Q.nfbind(nodeStyle)('foo').done((result: string) => {});

1
q/Q.d.ts vendored
View File

@@ -207,6 +207,7 @@ declare module Q {
export function invoke<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
export function mcall<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
export function denodeify<T>(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise<T>;
export function nfbind<T>(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise<T>;
export function nfcall<T>(nodeFunction: Function, ...args: any[]): Promise<T>;
export function nfapply<T>(nodeFunction: Function, args: any[]): Promise<T>;