forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed typing for async.parallel and co
- Loading branch information
1 parent
338059f
commit c3a6887
Showing
3 changed files
with
79 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// <reference path="async.d.ts" /> | ||
|
||
interface StringCallback { (err: Error, result: string): void; } | ||
interface AsyncStringGetter { (callback: StringCallback): void; } | ||
|
||
var taskArray: AsyncStringGetter[] = [ | ||
function (callback) { | ||
setTimeout(function () { | ||
callback(null, 'one'); | ||
}, 200); | ||
}, | ||
function (callback) { | ||
setTimeout(function () { | ||
callback(null, 'two'); | ||
}, 100); | ||
}, | ||
]; | ||
|
||
async.series(taskArray, function (err, results) { console.log(results[0].match(/o/)) }); | ||
async.parallel(taskArray, function (err, results) { console.log(results[0].match(/o/)) }); | ||
async.parallelLimit(taskArray, 3, function (err, results) { console.log(results[0].match(/o/)) }); | ||
|
||
|
||
interface Lookup<T> { [key: string]: T; } | ||
interface NumberCallback { (err: Error, result: number): void; } | ||
interface AsyncNumberGetter { (callback: NumberCallback): void; } | ||
|
||
var taskDict: Lookup<AsyncNumberGetter> = { | ||
one: function(callback){ | ||
setTimeout(function(){ | ||
callback(null, 1); | ||
}, 200); | ||
}, | ||
two: function(callback){ | ||
setTimeout(function(){ | ||
callback(null, 2); | ||
}, 100); | ||
} | ||
} | ||
|
||
async.series(taskDict, function(err, results) { console.log(results['one'].toFixed(1)) }); | ||
async.parallel(taskDict, function(err, results) { console.log(results['one'].toFixed(1)) }); | ||
async.parallelLimit(taskDict, 3, function(err, results) { console.log(results['one'].toFixed(1)) }); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--noImplicitAny |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters