Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#11906 from hleclerc/master
Browse files Browse the repository at this point in the history
modification/correction of signatures in module async
  • Loading branch information
yuit authored Nov 10, 2016
2 parents b8ce9ae + d5913e4 commit f92ec1f
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 158 deletions.
138 changes: 70 additions & 68 deletions async/async-tests.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
/// <reference path="async.d.ts" />

var fs, path;
/// <reference path="../node/node.d.ts" />
import * as fs from "fs";
// var fs = require("fs");

function callback() {}
function funcStringCbErrBoolean(v:string, cb:(err:Error,res:boolean) => void) {}

async.map(['file1', 'file2', 'file3'], fs.stat, function (err, results) { });
async.mapSeries(['file1', 'file2', 'file3'], fs.stat, function (err, results) { });
async.mapLimit(['file1', 'file2', 'file3'], 2, fs.stat, function (err, results) { });
async.map(['file1', 'file2', 'file3'], fs.stat, function (err:Error, results:Array<fs.Stats>) { });
async.mapSeries(['file1', 'file2', 'file3'], fs.stat, function (err:Error, results:Array<fs.Stats>) { });
async.mapLimit(['file1', 'file2', 'file3'], 2, fs.stat, function (err:Error, results:Array<fs.Stats>) { });

async.filter(['file1', 'file2', 'file3'], path.exists, function (results) { });
async.filterSeries(['file1', 'file2', 'file3'], path.exists, function (results) { });
async.filterLimit(['file1', 'file2', 'file3'], 2, path.exists, function (results) { });
async.select(['file1', 'file2', 'file3'], path.exists, function (results) { });
async.selectSeries(['file1', 'file2', 'file3'], path.exists, function (results) { });
async.selectLimit(['file1', 'file2', 'file3'], 2, path.exists, function (results) { });
async.filter(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array<string>) { });
async.filterSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array<string>) { });
async.filterLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err:Error,results:Array<string>) { });
async.select(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array<string>) { });
async.selectSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array<string>) { });
async.selectLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err:Error,results:Array<string>) { });

async.reject(['file1', 'file2', 'file3'], path.exists, function (results) { });
async.rejectSeries(['file1', 'file2', 'file3'], path.exists, function (results) { });
async.rejectLimit(['file1', 'file2', 'file3'], 2, path.exists, function (results) { });
async.reject(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array<string>) { });
async.rejectSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array<string>) { });
async.rejectLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err:Error,results:Array<string>) { });

async.parallel([
function () { },
Expand All @@ -41,9 +43,9 @@ var openFilesObj = {
file2: "fileTwo"
}

var saveFile = function () { }
async.each(openFiles, saveFile, function (err) { });
async.eachSeries(openFiles, saveFile, function (err) { });
var saveFile = function (file:string,cb:(err:Error)=>void) { }
async.each(openFiles, saveFile, function (err:Error) { });
async.eachSeries(openFiles, saveFile, function (err:Error) { });

var documents, requestApi;
async.eachLimit(documents, 20, requestApi, function (err) { });
Expand Down Expand Up @@ -73,23 +75,23 @@ async.foldl(numArray, 0, reducer, function (err, result) { });
async.reduceRight(numArray, 0, reducer, function (err, result) { });
async.foldr(numArray, 0, reducer, function (err, result) { });

async.detect(['file1', 'file2', 'file3'], path.exists, function (result) { });
async.detectSeries(['file1', 'file2', 'file3'], path.exists, function (result) { });
async.detectLimit(['file1', 'file2', 'file3'], 2, path.exists, function (result) { });
async.detect(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err,result:string) { });
async.detectSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err,result) { });
async.detectLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err,result) { });

async.sortBy(['file1', 'file2', 'file3'], function (file, callback) {
fs.stat(file, function (err, stats) {
callback(err, stats.mtime);
});
}, function (err, results) { });

async.some(['file1', 'file2', 'file3'], path.exists, function (result) { });
async.someLimit(['file1', 'file2', 'file3'], 2, path.exists, function (result) { });
async.any(['file1', 'file2', 'file3'], path.exists, function (result) { });
async.some(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,result:boolean) { });
async.someLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err:Error,result:boolean) { });
async.any(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,result:boolean) { });

async.every(['file1', 'file2', 'file3'], path.exists, function (result) { });
async.everyLimit(['file1', 'file2', 'file3'], 2, path.exists, function (result) { });
async.all(['file1', 'file2', 'file3'], path.exists, function (result) { });
async.every(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,result:boolean) { });
async.everyLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err:Error,result:boolean) { });
async.all(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,result:boolean) { });

async.concat(['dir1', 'dir2', 'dir3'], fs.readdir, function (err, files) { });
async.concatSeries(['dir1', 'dir2', 'dir3'], fs.readdir, function (err, files) { });
Expand All @@ -107,7 +109,7 @@ async.series([
],
function (err, results) { });

async.series<string>([
async.series<string,Error>([
function (callback) {
callback(null, 'one');
},
Expand All @@ -131,7 +133,7 @@ async.series({
},
function (err, results) { });

async.series<number>({
async.series<number,Error>({
one: function (callback) {
setTimeout(function () {
callback(null, 1);
Expand Down Expand Up @@ -171,7 +173,7 @@ async.parallel([
],
function (err, results) { });

async.parallel<string>([
async.parallel<string,Error>([
function (callback) {
setTimeout(function () {
callback(null, 'one');
Expand Down Expand Up @@ -200,7 +202,7 @@ async.parallel({
},
function (err, results) { });

async.parallel<number>({
async.parallel<number,Error>({
one: function (callback) {
setTimeout(function () {
callback(null, 1);
Expand Down Expand Up @@ -266,7 +268,7 @@ async.waterfall([
], function (err, result) { });


var q = async.queue<any>(function (task: any, callback) {
var q = async.queue<any,Error>(function (task: any, callback) {
console.log('hello ' + task.name);
callback();
}, 2);
Expand Down Expand Up @@ -319,7 +321,7 @@ q.resume();
q.kill();

// tests for strongly typed tasks
var q2 = async.queue<string>(function (task: string, callback) {
var q2 = async.queue<string,Error>(function (task: string, callback) {
console.log('Task: ' + task);
callback();
}, 1);
Expand Down Expand Up @@ -382,10 +384,10 @@ async.retry({ times: 3, interval: (retryCount) => { return 200 * retryCount; } }


async.parallel([
function (callback) { },
function (callback: ( err:Error, val:string ) => void ) { },
function (callback) { }
],
function (results) {
function (err:Error,results:Array<string>) {
async.series([
function (callback) { },
function email_link(callback) { }
Expand Down Expand Up @@ -438,10 +440,10 @@ async.dir(function (name, callback) {

// each

async.each<number>({
async.each<number,Error>({
"a": 1,
"b": 2
}, function(val: number, next: ErrorCallback): void {
}, function(val: number, next: ErrorCallback<Error>): void {

setTimeout(function(): void {

Expand All @@ -457,10 +459,10 @@ async.each<number>({

});

async.eachSeries<number>({
async.eachSeries<number, Error>({
"a": 1,
"b": 2
}, function(val: number, next: ErrorCallback): void {
}, function(val: number, next: ErrorCallback<Error>): void {

setTimeout(function(): void {

Expand All @@ -476,14 +478,14 @@ async.eachSeries<number>({

});

async.eachLimit<number>({
async.eachLimit<number, Error>({
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6
}, 2, function(val: number, next: ErrorCallback): void {
}, 2, function(val: number, next: ErrorCallback<Error>): void {

setTimeout(function(): void {

Expand All @@ -501,10 +503,10 @@ async.eachLimit<number>({

// forEachOf/eachOf

async.eachOf<number>({
async.eachOf<number, Error>({
"a": 1,
"b": 2
}, function(val: number, key: string, next: ErrorCallback): void {
}, function(val: number, key: string, next: ErrorCallback<Error>): void {

setTimeout(function(): void {

Expand All @@ -520,10 +522,10 @@ async.eachOf<number>({

});

async.forEachOfSeries<number>({
async.forEachOfSeries<number, Error>({
"a": 1,
"b": 2
}, function(val: number, key: string, next: ErrorCallback): void {
}, function(val: number, key: string, next: ErrorCallback<Error>): void {

setTimeout(function(): void {

Expand All @@ -539,14 +541,14 @@ async.forEachOfSeries<number>({

});

async.forEachOfLimit<number>({
async.forEachOfLimit<number, Error>({
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6
}, 2, function(val: number, key: string, next: ErrorCallback): void {
}, 2, function(val: number, key: string, next: ErrorCallback<Error>): void {

setTimeout(function(): void {

Expand All @@ -564,11 +566,11 @@ async.forEachOfLimit<number>({

// map

async.map<number, string>({
async.map<number, string, Error>({
"a": 1,
"b": 2,
"c": 3
}, function(val: number, next: AsyncResultCallback<string>): void {
}, function(val: number, next: AsyncResultCallback<string, Error>): void {

setTimeout(function(): void {

Expand All @@ -584,11 +586,11 @@ async.map<number, string>({

});

async.mapSeries<number, string>({
async.mapSeries<number, string, Error>({
"a": 1,
"b": 2,
"c": 3
}, function(val: number, next: AsyncResultCallback<string>): void {
}, function(val: number, next: AsyncResultCallback<string, Error>): void {

setTimeout(function(): void {

Expand All @@ -604,14 +606,14 @@ async.mapSeries<number, string>({

});

async.mapLimit<number, string>({
async.mapLimit<number, string, Error>({
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6
}, 2, function(val: number, next: AsyncResultCallback<string>): void {
}, 2, function(val: number, next: AsyncResultCallback<string, Error>): void {

setTimeout(function(): void {

Expand All @@ -629,11 +631,11 @@ async.mapLimit<number, string>({

// mapValues

async.mapValues<number, string>({
async.mapValues<number, string, Error>({
"a": 1,
"b": 2,
"c": 3
}, function(val: number, key: string, next: AsyncResultCallback<string>): void {
}, function(val: number, key: string, next: AsyncResultCallback<string, Error>): void {

setTimeout(function(): void {

Expand All @@ -649,11 +651,11 @@ async.mapValues<number, string>({

});

async.mapValuesSeries<number, string>({
async.mapValuesSeries<number, string, Error>({
"a": 1,
"b": 2,
"c": 3
}, function(val: number, key: string, next: AsyncResultCallback<string>): void {
}, function(val: number, key: string, next: AsyncResultCallback<string, Error>): void {

setTimeout(function(): void {

Expand All @@ -671,11 +673,11 @@ async.mapValuesSeries<number, string>({

// filter/select/reject

async.filter<number>({
async.filter<number, Error>({
"a": 1,
"b": 2,
"c": 3
}, function(val: number, next: AsyncBooleanResultCallback): void {
}, function(val: number, next: AsyncBooleanResultCallback<Error>): void {

setTimeout(function(): void {

Expand All @@ -691,11 +693,11 @@ async.filter<number>({

});

async.reject<number>({
async.reject<number, Error>({
"a": 1,
"b": 2,
"c": 3
}, function(val: number, next: AsyncBooleanResultCallback): void {
}, function(val: number, next: AsyncBooleanResultCallback<Error>): void {

setTimeout(function(): void {

Expand All @@ -713,11 +715,11 @@ async.reject<number>({

// concat

async.concat<string, string>({
async.concat<string, string, Error>({
"a": "1",
"b": "2",
"c": "3"
}, function(item: string, next: AsyncResultCallback<string[]>): void {
}, function(item: string, next: AsyncResultCallback<string[], Error>): void {

console.log(`async.concat: ${item}`);

Expand All @@ -731,11 +733,11 @@ async.concat<string, string>({

// detect/find

async.detect<number>({
async.detect<number, Error>({
"a": 1,
"b": 2,
"c": 3
}, function(item: number, next: AsyncBooleanResultCallback): void {
}, function(item: number, next: AsyncBooleanResultCallback<Error>): void {

console.log(`async.detect/find: ${item}`);

Expand All @@ -756,11 +758,11 @@ async.detect<number>({

// every/all

async.every<number>({
async.every<number,Error>({
"a": 1,
"b": 2,
"c": 3
}, function(item: number, next: AsyncBooleanResultCallback): void {
}, function(item: number, next: AsyncBooleanResultCallback<Error>): void {

console.log(`async.every/all: ${item}`);

Expand All @@ -774,11 +776,11 @@ async.every<number>({

// some/any

async.some<number>({
async.some<number, Error>({
"a": 1,
"b": 2,
"c": 3
}, function(item: number, next: AsyncBooleanResultCallback): void {
}, function(item: number, next: AsyncBooleanResultCallback<Error>): void {

console.log(`async.some/any: ${item}`);

Expand Down
Loading

0 comments on commit f92ec1f

Please sign in to comment.