From 48a2c183842b9f8ca1141e5f6fa3f0bbcd23fed0 Mon Sep 17 00:00:00 2001 From: Michel Salib Date: Tue, 10 Jun 2014 16:43:12 +0200 Subject: [PATCH] Adding denodeify definition for Q --- q/Q-tests.ts | 8 +++++--- q/Q.d.ts | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/q/Q-tests.ts b/q/Q-tests.ts index 6b69fb228c..56ce130f0a 100644 --- a/q/Q-tests.ts +++ b/q/Q-tests.ts @@ -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; declare function saveToCloud(): Q.Promise; -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) => {}); \ No newline at end of file diff --git a/q/Q.d.ts b/q/Q.d.ts index 65b2b8223d..af3e8bea07 100644 --- a/q/Q.d.ts +++ b/q/Q.d.ts @@ -207,6 +207,7 @@ declare module Q { export function invoke(obj: any, functionName: string, ...args: any[]): Promise; export function mcall(obj: any, functionName: string, ...args: any[]): Promise; + export function denodeify(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise; export function nfbind(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise; export function nfcall(nodeFunction: Function, ...args: any[]): Promise; export function nfapply(nodeFunction: Function, args: any[]): Promise;