diff --git a/types/async/index.d.ts b/types/async/index.d.ts index e6cfd3bcaa..05d99e5968 100644 --- a/types/async/index.d.ts +++ b/types/async/index.d.ts @@ -1,13 +1,18 @@ -// Type definitions for Async 2.0.1 +// Type definitions for Async 2.4 // Project: https://github.com/caolan/async -// Definitions by: Boris Yankov , Arseniy Maximov , Joe Herman , Angus Fenying , Pascal Martin +// Definitions by: Boris Yankov +// Arseniy Maximov +// Joe Herman +// Angus Fenying +// Pascal Martin +// Dmitri Trofimov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 export as namespace async; export interface Dictionary { [key: string]: T; } -export type IterableCollection = T[] | IterableIterator | Dictionary +export type IterableCollection = T[] | IterableIterator | Dictionary; export interface ErrorCallback { (err?: E | null): void; } export interface AsyncBooleanResultCallback { (err?: E | null, truthValue?: boolean): void; } @@ -26,30 +31,40 @@ export interface AsyncBooleanIterator { (item: T, callback: AsyncB export interface AsyncWorker { (task: T, callback: ErrorCallback): void; } export interface AsyncVoidFunction { (callback: ErrorCallback): void; } -export type AsyncAutoTasks, E> = { [K in keyof R]: AsyncAutoTask } -export type AsyncAutoTask, E> = AsyncAutoTaskFunctionWithoutDependencies | (keyof R | AsyncAutoTaskFunction)[]; +export type AsyncAutoTasks, E> = { [K in keyof R]: AsyncAutoTask }; +export type AsyncAutoTask, E> = AsyncAutoTaskFunctionWithoutDependencies | Array>; export interface AsyncAutoTaskFunctionWithoutDependencies { (cb: AsyncResultCallback | ErrorCallback): void; } export interface AsyncAutoTaskFunction, E = Error> { (results: R, cb: AsyncResultCallback | ErrorCallback): void; } +export interface DataContainer { + data: T; +} + +export interface CallbackContainer { + callback: Function; +} + +export interface PriorityContainer { + priority: number; +} + export interface AsyncQueue { length(): number; started: boolean; running(): number; idle(): boolean; concurrency: number; - push(task: T | T[], callback?: AsyncResultCallback): void; + push(task: T | T[], callback?: AsyncResultCallback): void; unshift(task: T | T[], callback?: ErrorCallback): void; + remove(filter: (node: DataContainer) => boolean): void; saturated: () => any; empty: () => any; drain: () => any; paused: boolean; - pause(): void + pause(): void; resume(): void; kill(): void; - workersList(): { - data: T, - callback: Function - }[]; + workersList, CallbackContainer>(): TWorker[]; error(error: Error, data: any): void; unsaturated(): void; buffer: number; @@ -60,7 +75,7 @@ export interface AsyncPriorityQueue { concurrency: number; started: boolean; paused: boolean; - push(task: T | T[], priority: number, callback?: AsyncResultArrayCallback): void; + push(task: T | T[], priority: number, callback?: AsyncResultArrayCallback): void; saturated: () => any; empty: () => any; drain: () => any; @@ -69,11 +84,7 @@ export interface AsyncPriorityQueue { pause(): void; resume(): void; kill(): void; - workersList(): { - data: T, - priority: number, - callback: Function - }[]; + workersList, CallbackContainer, PriorityContainer>(): TWorker[]; error(error: Error, data: any): void; unsaturated(): void; buffer: number; @@ -82,7 +93,7 @@ export interface AsyncPriorityQueue { export interface AsyncCargo { length(): number; payload?: number; - push(task: any, callback? : Function): void; + push(task: any, callback?: Function): void; saturated(): void; empty(): void; drain(): void; @@ -105,11 +116,17 @@ export function forEachOfLimit(obj: IterableCollection, limit: export const eachOf: typeof forEachOf; export const eachOfSeries: typeof forEachOf; export const eachOfLimit: typeof forEachOfLimit; -export function map(arr: T[] | IterableIterator, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; -export function map(arr: Dictionary, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; +export function map(arr: T[] | IterableIterator | Dictionary, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; export const mapSeries: typeof map; export function mapLimit(arr: IterableCollection, limit: number, iterator: AsyncResultIterator, callback?: AsyncResultArrayCallback): void; -export function mapValuesLimit(obj: Dictionary, limit: number, iteratee: (value: T, key: string, callback: AsyncResultCallback) => void, callback: AsyncResultObjectCallback): void; + +export function mapValuesLimit( + obj: Dictionary, + limit: number, + iteratee: (value: T, key: string, callback: AsyncResultCallback) => void, + callback: AsyncResultObjectCallback + ): void; + export function mapValues(obj: Dictionary, iteratee: (value: T, key: string, callback: AsyncResultCallback) => void, callback: AsyncResultObjectCallback): void; export const mapValuesSeries: typeof mapValues; export function filter(arr: IterableCollection, iterator: AsyncBooleanIterator, callback?: AsyncResultArrayCallback): void; @@ -151,7 +168,7 @@ export function concatLimit(arr: IterableCollection, limit: export const concatSeries: typeof concat; // Control Flow -export function series(tasks: AsyncFunction[], callback?: AsyncResultArrayCallback): void; +export function series(tasks: Array>, callback?: AsyncResultArrayCallback): void; export function series(tasks: Dictionary>, callback?: AsyncResultObjectCallback): void; export function parallel(tasks: Array>, callback?: AsyncResultArrayCallback): void; export function parallel(tasks: Dictionary>, callback?: AsyncResultObjectCallback): void; @@ -161,9 +178,9 @@ export function whilst(test: () => boolean, fn: AsyncVoidFunction, export function doWhilst(fn: AsyncFunctionEx, test: (...results: T[]) => boolean, callback: ErrorCallback): void; export function until(test: () => boolean, fn: AsyncVoidFunction, callback: ErrorCallback): void; export function doUntil(fn: AsyncFunctionEx, test: (...results: T[]) => boolean, callback: ErrorCallback): void; -export function during(test: (testCallback : AsyncBooleanResultCallback) => void, fn: AsyncVoidFunction, callback: ErrorCallback): void; +export function during(test: (testCallback: AsyncBooleanResultCallback) => void, fn: AsyncVoidFunction, callback: ErrorCallback): void; export function doDuring(fn: AsyncVoidFunction, test: (testCallback: AsyncBooleanResultCallback) => void, callback: ErrorCallback): void; -export function forever(next: (next : ErrorCallback) => void, errBack: ErrorCallback) : void; +export function forever(next: (next: ErrorCallback) => void, errBack: ErrorCallback): void; export function waterfall(tasks: Function[], callback?: AsyncResultCallback): void; export function compose(...fns: Function[]): Function; export function seq(...fns: Function[]): Function; @@ -172,34 +189,52 @@ export function applyEachSeries(fns: Function[], ...argsAndCallback: any[]): voi export function queue(worker: AsyncWorker, concurrency?: number): AsyncQueue; export function queue(worker: AsyncResultIterator, concurrency?: number): AsyncQueue; export function priorityQueue(worker: AsyncWorker, concurrency: number): AsyncPriorityQueue; -export function cargo(worker : (tasks: any[], callback : ErrorCallback) => void, payload? : number) : AsyncCargo; +export function cargo(worker: (tasks: any[], callback: ErrorCallback) => void, payload?: number): AsyncCargo; export function auto, E = Error>(tasks: AsyncAutoTasks, concurrency?: number, callback?: AsyncResultCallback): void; export function auto, E = Error>(tasks: AsyncAutoTasks, callback?: AsyncResultCallback): void; export function autoInject(tasks: any, callback?: AsyncResultCallback): void; -export function retry(opts: number, task: (callback : AsyncResultCallback, results: any) => void, callback: AsyncResultCallback): void; -export function retry(opts: { times: number, interval: number|((retryCount: number) => number) }, task: (callback: AsyncResultCallback, results : any) => void, callback: AsyncResultCallback): void; + +export function retry( + opts: number | { + times: number, + interval: number | ((retryCount: number) => number) + }, + task: (callback: AsyncResultCallback, results: any) => void, + callback: AsyncResultCallback + ): void; + export function retryable(opts: number | {times: number, interval: number}, task: AsyncFunction): AsyncFunction; -export function apply(fn: Function, ...args: any[]): AsyncFunction; +export function apply(fn: Function, ...args: any[]): AsyncFunction; export function nextTick(callback: Function, ...args: any[]): void; export const setImmediate: typeof nextTick; -export function reflect(fn: AsyncFunction) : (callback: (err: null, result: {error?: E, value?: T}) => void) => void; -export function reflectAll(tasks: AsyncFunction[]): ((callback: (err: null, result: {error?: E, value?: T}) => void) => void)[]; +export function reflect(fn: AsyncFunction): (callback: (err: null, result: {error?: E, value?: T}) => void) => void; +export function reflectAll(tasks: Array>): Array<(callback: (err: null, result: {error?: E, value?: T}) => void) => void>; export function timeout(fn: AsyncFunction, milliseconds: number, info?: any): AsyncFunction; export function timeout(fn: AsyncResultIterator, milliseconds: number, info?: any): AsyncResultIterator; -export function times (n: number, iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): void; +export function times(n: number, iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): void; export function timesSeries(n: number, iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): void; export function timesLimit(n: number, limit: number, iterator: AsyncResultIterator, callback: AsyncResultArrayCallback): void; export function transform(arr: T[], iteratee: (acc: R[], item: T, key: number, callback: (error?: E) => void) => void, callback?: AsyncResultArrayCallback): void; export function transform(arr: T[], acc: R[], iteratee: (acc: R[], item: T, key: number, callback: (error?: E) => void) => void, callback?: AsyncResultArrayCallback): void; -export function transform(arr: {[key: string] : T}, iteratee: (acc: {[key: string] : R}, item: T, key: string, callback: (error?: E) => void) => void, callback?: AsyncResultObjectCallback): void; -export function transform(arr: {[key: string] : T}, acc: {[key: string] : R}, iteratee: (acc: {[key: string] : R}, item: T, key: string, callback: (error?: E) => void) => void, callback?: AsyncResultObjectCallback): void; +export function transform( + arr: {[key: string]: T}, + iteratee: (acc: {[key: string]: R}, item: T, key: string, callback: (error?: E) => void) => void, + callback?: AsyncResultObjectCallback + ): void; -export function race(tasks: (AsyncFunction)[], callback: AsyncResultCallback) : void; +export function transform( + arr: {[key: string]: T}, + acc: {[key: string]: R}, + iteratee: (acc: {[key: string]: R}, item: T, key: string, callback: (error?: E) => void) => void, + callback?: AsyncResultObjectCallback + ): void; + +export function race(tasks: Array>, callback: AsyncResultCallback): void; // Utils export function memoize(fn: Function, hasher?: Function): Function; diff --git a/types/async/test/es6-generators.ts b/types/async/test/es6-generators.ts index b67e7daad7..e0008d7d5e 100644 --- a/types/async/test/es6-generators.ts +++ b/types/async/test/es6-generators.ts @@ -10,45 +10,45 @@ function eachOfIterator(item: T, key: K, callback: (err: Error) => void function concatIterator(item: T, callback: (err: E, res: R[]) => void) { } -async.map(collectionGenerator(), funcMapIterator, funcMapComplete) -async.mapSeries(collectionGenerator(), funcMapIterator, funcMapComplete) -async.mapLimit(collectionGenerator(), 2, funcMapIterator, funcMapComplete) +async.map(collectionGenerator(), funcMapIterator, funcMapComplete); +async.mapSeries(collectionGenerator(), funcMapIterator, funcMapComplete); +async.mapLimit(collectionGenerator(), 2, funcMapIterator, funcMapComplete); -async.filter(collectionGenerator(), booleanIterator, function (err: Error, results: any[]) { }) -async.filterSeries(collectionGenerator(), booleanIterator, function (err: Error, results: any[]) { }) -async.filterLimit(collectionGenerator(), 2, booleanIterator, function (err: Error, results: any[]) { }) -async.select(collectionGenerator(), booleanIterator, function (err: Error, results: any[]) { }) -async.selectSeries(collectionGenerator(), booleanIterator, function (err: Error, results: any[]) { }) -async.selectLimit(collectionGenerator(), 2, booleanIterator, function (err: Error, results: any[]) { }) +async.filter(collectionGenerator(), booleanIterator, (err: Error, results: any[]) => { }); +async.filterSeries(collectionGenerator(), booleanIterator, (err: Error, results: any[]) => { }); +async.filterLimit(collectionGenerator(), 2, booleanIterator, (err: Error, results: any[]) => { }); +async.select(collectionGenerator(), booleanIterator, (err: Error, results: any[]) => { }); +async.selectSeries(collectionGenerator(), booleanIterator, (err: Error, results: any[]) => { }); +async.selectLimit(collectionGenerator(), 2, booleanIterator, (err: Error, results: any[]) => { }); -async.reject(collectionGenerator(), booleanIterator, function (err: Error, results: any[]) { }) -async.rejectSeries(collectionGenerator(), booleanIterator, function (err: Error, results: any[]) { }) -async.rejectLimit(collectionGenerator(), 2, booleanIterator, function (err: Error, results: any[]) { }) +async.reject(collectionGenerator(), booleanIterator, (err: Error, results: any[]) => { }); +async.rejectSeries(collectionGenerator(), booleanIterator, (err: Error, results: any[]) => { }); +async.rejectLimit(collectionGenerator(), 2, booleanIterator, (err: Error, results: any[]) => { }); -async.each(collectionGenerator(), eachIterator, function (err: Error) { }) -async.eachLimit(collectionGenerator(), 2, eachIterator, function (err: Error) { }) -async.eachSeries(collectionGenerator(), eachIterator, function (err: Error) { }) -async.eachOf(collectionGenerator(), eachOfIterator, function (err: Error) { }) -async.eachOfLimit(collectionGenerator(), 2, eachOfIterator, function (err: Error) { }) -async.eachOfSeries(collectionGenerator(), eachOfIterator, function (err: Error) { }) -async.forEach(collectionGenerator(), eachIterator, function (err: Error) { }) -async.forEachLimit(collectionGenerator(), 2, eachIterator, function (err: Error) { }) -async.forEachSeries(collectionGenerator(), eachIterator, function (err: Error) { }) -async.forEachOf(collectionGenerator(), eachOfIterator, function (err: Error) { }) -async.forEachOfLimit(collectionGenerator(), 2, eachOfIterator, function (err: Error) { }) -async.forEachOfSeries(collectionGenerator(), eachOfIterator, function (err: Error) { }) +async.each(collectionGenerator(), eachIterator, (err: Error) => { }); +async.eachLimit(collectionGenerator(), 2, eachIterator, (err: Error) => { }); +async.eachSeries(collectionGenerator(), eachIterator, (err: Error) => { }); +async.eachOf(collectionGenerator(), eachOfIterator, (err: Error) => { }); +async.eachOfLimit(collectionGenerator(), 2, eachOfIterator, (err: Error) => { }); +async.eachOfSeries(collectionGenerator(), eachOfIterator, (err: Error) => { }); +async.forEach(collectionGenerator(), eachIterator, (err: Error) => { }); +async.forEachLimit(collectionGenerator(), 2, eachIterator, (err: Error) => { }); +async.forEachSeries(collectionGenerator(), eachIterator, (err: Error) => { }); +async.forEachOf(collectionGenerator(), eachOfIterator, (err: Error) => { }); +async.forEachOfLimit(collectionGenerator(), 2, eachOfIterator, (err: Error) => { }); +async.forEachOfSeries(collectionGenerator(), eachOfIterator, (err: Error) => { }); -async.every(collectionGenerator(), booleanIterator, function (err: Error, res: boolean) { }) -async.everyLimit(collectionGenerator(), 2, booleanIterator, function (err: Error, res: boolean) { }) -async.everySeries(collectionGenerator(), booleanIterator, function (err: Error, res: boolean) { }) +async.every(collectionGenerator(), booleanIterator, (err: Error, res: boolean) => { }); +async.everyLimit(collectionGenerator(), 2, booleanIterator, (err: Error, res: boolean) => { }); +async.everySeries(collectionGenerator(), booleanIterator, (err: Error, res: boolean) => { }); -async.some(collectionGenerator(), booleanIterator, function (err: Error, res: boolean) { }) -async.someLimit(collectionGenerator(), 2, booleanIterator, function (err: Error, res: boolean) { }) -async.someSeries(collectionGenerator(), booleanIterator, function (err: Error, res: boolean) { }) +async.some(collectionGenerator(), booleanIterator, (err: Error, res: boolean) => { }); +async.someLimit(collectionGenerator(), 2, booleanIterator, (err: Error, res: boolean) => { }); +async.someSeries(collectionGenerator(), booleanIterator, (err: Error, res: boolean) => { }); -async.detect(collectionGenerator(), booleanIterator, function (err: Error, res: boolean) { }) -async.detectLimit(collectionGenerator(), 2, booleanIterator, function (err: Error, res: boolean) { }) -async.detectSeries(collectionGenerator(), booleanIterator, function (err: Error, res: boolean) { }) +async.detect(collectionGenerator(), booleanIterator, (err: Error, res: boolean) => { }); +async.detectLimit(collectionGenerator(), 2, booleanIterator, (err: Error, res: boolean) => { }); +async.detectSeries(collectionGenerator(), booleanIterator, (err: Error, res: boolean) => { }); -async.concat(collectionGenerator(), concatIterator, (err: Error, res: any[]) => { }) -async.concatSeries(collectionGenerator(), concatIterator, (err: Error, res: any[]) => { }) +async.concat(collectionGenerator(), concatIterator, (err: Error, res: any[]) => { }); +async.concatSeries(collectionGenerator(), concatIterator, (err: Error, res: any[]) => { }); diff --git a/types/async/test/explicit.ts b/types/async/test/explicit.ts index 0c0e1a44ee..ae97888531 100644 --- a/types/async/test/explicit.ts +++ b/types/async/test/explicit.ts @@ -1,74 +1,58 @@ - - interface StringCallback { (err?: Error, result?: string): void; } interface AsyncStringGetter { (callback: StringCallback): void; } -var taskArray: AsyncStringGetter[] = [ - function (callback) { - setTimeout(function () { - callback(undefined, 'one'); - }, 200); - }, - function (callback) { - setTimeout(function () { - callback(undefined, 'two'); - }, 100); - }, +const taskArray: AsyncStringGetter[] = [ + callback => { setTimeout(() => { callback(undefined, 'one'); }, 200); }, + callback => { setTimeout(() => { callback(undefined, 'two'); }, 100); } ]; -async.series(taskArray, function (err, results) { +async.series(taskArray, (err, results) => { if (results) { - let first = results[0]; + const first = results[0]; if (first) { - console.log(first.match(/o/)) - } - } -}); -async.parallel(taskArray, function (err, results) { - if (results) { - let first = results[0]; - if (first) { - console.log(first.match(/o/)) - } - } -}); -async.parallelLimit(taskArray, 3, function (err, results) { - if (results) { - let first = results[0]; - if (first) { - console.log(first.match(/o/)) + console.log(first.match(/o/)); } } }); +async.parallel(taskArray, (err, results) => { + if (results) { + const first = results[0]; + if (first) { + console.log(first.match(/o/)); + } + } +}); + +async.parallelLimit(taskArray, 3, (err, results) => { + if (results) { + const first = results[0]; + if (first) { + console.log(first.match(/o/)); + } + } +}); interface Lookup { [key: string]: T; } interface NumberCallback { (err?: Error, result?: number): void; } interface AsyncNumberGetter { (callback: NumberCallback): void; } -var taskDict: Lookup = { - one: function(callback) { - setTimeout(function() { - callback(undefined, 1); - }, 200); - }, - two: function(callback) { - setTimeout(function() { - callback(undefined, 2); - }, 100); - } -} +const taskDict: Lookup = { + one: callback => { setTimeout(() => { callback(undefined, 1); }, 200); }, + two: callback => { setTimeout(() => { callback(undefined, 2); }, 100); } +}; -async.series(taskDict, function(err, results) { - let one = results['one']; - console.log(one && one.toFixed(1)) -}); -async.parallel(taskDict, function(err, results) { - let one = results['one']; - console.log(one && one.toFixed(1)) -}); -async.parallelLimit(taskDict, 3, function(err, results) { - let one = results['one']; - console.log(one && one.toFixed(1)) +async.series(taskDict, (err, results) => { + const one = results['one']; + console.log(one && one.toFixed(1)); }); +async.parallel(taskDict, (err, results) => { + const one = results['one']; + console.log(one && one.toFixed(1)); +}); + +async.parallelLimit(taskDict, 3, (err, results) => { + const one = results['one']; + console.log(one && one.toFixed(1)); +}); diff --git a/types/async/test/index.ts b/types/async/test/index.ts index 574a5ed8b9..97e888870b 100644 --- a/types/async/test/index.ts +++ b/types/async/test/index.ts @@ -9,406 +9,272 @@ declare var path: { exists: (path: string, callback?: (err: Error, exists: boolean) => any) => void; }; -function funcStringCbErrBoolean(v:string, cb:(err:Error,res:boolean) => void) {} +function funcStringCbErrBoolean(v: string, cb: (err: Error, res: boolean) => void) {} function callback() { } -async.map(['file1', 'file2', 'file3'], fs.stat, function (err:Error, results:Array) { }); -async.mapSeries(['file1', 'file2', 'file3'], fs.stat, function (err:Error, results:Array) { }); -async.mapLimit(['file1', 'file2', 'file3'], 2, fs.stat, function (err:Error, results:Array) { }); +async.map(['file1', 'file2', 'file3'], fs.stat, (err: Error, results: fs.Stats[]) => { }); +async.mapSeries(['file1', 'file2', 'file3'], fs.stat, (err: Error, results: fs.Stats[]) => { }); +async.mapLimit(['file1', 'file2', 'file3'], 2, fs.stat, (err: Error, results: fs.Stats[]) => { }); -async.filter(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array) { }); -async.filterSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array) { }); -async.filterLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err:Error,results:Array) { }); -async.select(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array) { }); -async.selectSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array) { }); -async.selectLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err:Error,results:Array) { }); +async.filter(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, results: string[]) => { }); +async.filterSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, results: string[]) => { }); +async.filterLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, (err: Error, results: string[]) => { }); +async.select(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, results: string[]) => { }); +async.selectSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, results: string[]) => { }); +async.selectLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, (err: Error, results: string[]) => { }); -async.reject(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array) { }); -async.rejectSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err:Error,results:Array) { }); -async.rejectLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err:Error,results:Array) { }); +async.reject(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, results: string[]) => { }); +async.rejectSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, results: string[]) => { }); +async.rejectLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, (err: Error, results: string[]) => { }); async.parallel([ - function () { }, - function () { } + () => { }, + () => { } ], callback); async.series([ - function () { }, - function () { } + () => { }, + () => { } ]); -var data: any[] = []; +const data: any[] = []; function asyncProcess(item: any, callback: (err: Error, result: any) => void) { } -async.map(data, asyncProcess, function (err, results) { - console.log(results); -}); +async.map(data, asyncProcess, (err, results) => { console.log(results); }); -var openFiles = ['file1', 'file2']; -var openFilesObj = { +const openFiles = ['file1', 'file2']; +const openFilesObj = { file1: "fileOne", file2: "fileTwo" -} +}; -var saveFile = function (file:string,cb:(err:Error)=>void) { } -async.each(openFiles, saveFile, function (err:Error) { }); -async.eachSeries(openFiles, saveFile, function (err:Error) { }); +const saveFile = (file: string, cb: (err: Error) => void) => { }; +async.each(openFiles, saveFile, (err: Error) => { }); +async.eachSeries(openFiles, saveFile, (err: Error) => { }); -var documents: any, requestApi: any; -async.eachLimit(documents, 20, requestApi, function (err) { }); +const documents: any[] = []; +const requestApi: async.AsyncIterator = () => { }; +async.eachLimit(documents, 20, requestApi, err => { }); // forEachOf* functions. May accept array or object. function forEachOfIterator(item: string, key: string, forEachOfIteratorCallback: any) { - console.log("ForEach: item=" + item + ", key=" + key); + console.log(`ForEach: item=${item}, key=${key}`); forEachOfIteratorCallback(); } -async.forEachOf(openFiles, forEachOfIterator, function (err) { }); -async.forEachOf(openFilesObj, forEachOfIterator, function (err) { }); -async.forEachOfSeries(openFiles, forEachOfIterator, function (err) { }); -async.forEachOfSeries(openFilesObj, forEachOfIterator, function (err) { }); -async.forEachOfLimit(openFiles, 2, forEachOfIterator, function (err) { }); -async.forEachOfLimit(openFilesObj, 2, forEachOfIterator, function (err) { }); +async.forEachOf(openFiles, forEachOfIterator, err => { }); +async.forEachOf(openFilesObj, forEachOfIterator, err => { }); +async.forEachOfSeries(openFiles, forEachOfIterator, err => { }); +async.forEachOfSeries(openFilesObj, forEachOfIterator, err => { }); +async.forEachOfLimit(openFiles, 2, forEachOfIterator, err => { }); +async.forEachOfLimit(openFilesObj, 2, forEachOfIterator, err => { }); -var numArray = [1, 2, 3]; +const numArray = [1, 2, 3]; function reducer(memo: any, item: any, callback: any) { - process.nextTick(function () { - callback(null, memo + item) - }); + process.nextTick(() => { callback(null, memo + item); }); } -async.reduce(numArray, 0, reducer, function (err, result) { }); -async.inject(numArray, 0, reducer, function (err, result) { }); -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'], funcStringCbErrBoolean, function (err: Error,result:string) { }); -async.detectSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, function (err,result) { }); -async.detectLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, function (err,result) { }); +async.reduce(numArray, 0, reducer, (err, result) => { }); +async.inject(numArray, 0, reducer, (err, result) => { }); +async.foldl(numArray, 0, reducer, (err, result) => { }); +async.reduceRight(numArray, 0, reducer, (err, result) => { }); +async.foldr(numArray, 0, reducer, (err, result) => { }); -async.sortBy(['file1', 'file2', 'file3'], function (file, callback) { - fs.stat(file, function (err, stats) { - callback(err, stats.mtime); - }); -}, function (err, results) { }); +async.detect(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, result: string) => { }); +async.detectSeries(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err, result) => { }); +async.detectLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, (err, 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.sortBy(['file1', 'file2', 'file3'], (file, callback) => { + fs.stat(file, (err, stats) => { callback(err, stats.mtime); }); +}, (err, results) => { }); -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.some(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, result: boolean) => { }); +async.someLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, (err: Error, result: boolean) => { }); +async.any(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, result: boolean) => { }); -async.concat(['dir1', 'dir2', 'dir3'], fs.readdir, function (err, files) { }); -async.concatSeries(['dir1', 'dir2', 'dir3'], fs.readdir, function (err, files) { }); +async.every(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, result: boolean) => { }); +async.everyLimit(['file1', 'file2', 'file3'], 2, funcStringCbErrBoolean, (err: Error, result: boolean) => { }); +async.all(['file1', 'file2', 'file3'], funcStringCbErrBoolean, (err: Error, result: boolean) => { }); +async.concat(['dir1', 'dir2', 'dir3'], fs.readdir, (err, files) => { }); +async.concatSeries(['dir1', 'dir2', 'dir3'], fs.readdir, (err, files) => { }); // Control Flow // -async.series([ - function (callback) { - callback(undefined, 'one'); - }, - function (callback) { - callback(undefined, 'two'); - }, -], -function (err, results) { }); - -async.series([ - function (callback) { - callback(undefined, 'one'); - }, - function (callback) { - callback(undefined, 'two'); - }, -], -function (err, results) { }); +async.series([callback => { callback(undefined, 'one'); }, callback => { callback(undefined, 'two'); }], (err, results) => { }); +async.series([callback => { callback(undefined, 'one'); }, callback => { callback(undefined, 'two'); }], (err, results) => { }); async.series({ - one: function (callback) { - setTimeout(function () { - callback(undefined, 1); - }, 200); + one: callback => { setTimeout(() => { callback(undefined, 1); }, 200); }, + two: callback => { setTimeout(() => { callback(undefined, 2); }, 100); } }, - two: function (callback) { - setTimeout(function () { - callback(undefined, 2); - }, 100); - }, -}, -function (err, results) { }); + (err, results) => { }); async.series({ - one: function (callback) { - setTimeout(function () { - callback(undefined, 1); - }, 200); + one: callback => { setTimeout(() => { callback(undefined, 1); }, 200); }, + two: callback => { setTimeout(() => { callback(undefined, 2); }, 100); } }, - two: function (callback) { - setTimeout(function () { - callback(undefined, 2); - }, 100); - }, -}, -function (err, results) { }); + (err, results) => { }); -async.times(5, function(n, next) { - next(undefined as any, n) -}, function(err, results) { - console.log(results) -}) +async.times(5, (n, next) => { next(undefined as any, n); }, (err, results) => { console.log(results); }); -async.timesSeries(5, function(n, next) { - next(undefined as any, n) -}, function(err, results) { - console.log(results) -}) +async.timesSeries(5, (n, next) => { next(undefined as any, n); }, (err, results) => { console.log(results); }); async.parallel([ - function (callback) { - setTimeout(function () { - callback(undefined, 'one'); - }, 200); - }, - function (callback) { - setTimeout(function () { - callback(undefined, 'two'); - }, 100); - }, -], -function (err, results) { }); + callback => { setTimeout(() => { callback(undefined, 'one'); }, 200); }, + callback => { setTimeout(() => { callback(undefined, 'two'); }, 100); } + ], + (err, results) => { }); async.parallel([ - function (callback) { - setTimeout(function () { - callback(undefined, 'one'); - }, 200); - }, - function (callback) { - setTimeout(function () { - callback(undefined, 'two'); - }, 100); - }, -], -function (err, results) { }); - + callback => { setTimeout(() => { callback(undefined, 'one'); }, 200); }, + callback => { setTimeout(() => { callback(undefined, 'two'); }, 100); } + ], + (err, results) => { }); async.parallel({ - one: function (callback) { - setTimeout(function () { - callback(undefined, 1); - }, 200); + one: callback => { setTimeout(() => { callback(undefined, 1); }, 200); }, + two: callback => { setTimeout(() => { callback(undefined, 2); }, 100); } }, - two: function (callback) { - setTimeout(function () { - callback(undefined, 2); - }, 100); - }, -}, -function (err, results) { }); + (err, results) => { }); async.parallel({ - one: function (callback) { - setTimeout(function () { - callback(undefined, 1); - }, 200); + one: callback => { setTimeout(() => { callback(undefined, 1); }, 200); }, + two: callback => { setTimeout(() => { callback(undefined, 2); }, 100); } }, - two: function (callback) { - setTimeout(function () { - callback(undefined, 2); - }, 100); - }, -}, - function (err, results) { }); + (err, results) => { }); async.parallelLimit({ - one: function (callback) { - setTimeout(function () { - callback(undefined, 1); - }, 200); + one: callback => { setTimeout(() => { callback(undefined, 1); }, 200); }, + two: callback => { setTimeout(() => { callback(undefined, 2); }, 100); } }, - two: function (callback) { - setTimeout(function () { - callback(undefined, 2); - }, 100); - }, -}, 2, - function (err, results) { } + (err, results) => { } ); - function whileFn(callback: any) { setTimeout(() => callback(null, ++count), 1000); } function whileTest() { return count < 5; } function doWhileTest(count: number) { return count < 5; } -var count = 0; -async.whilst(whileTest, whileFn, function (err) { }); -async.until(whileTest, whileFn, function (err) { }); -async.doWhilst(whileFn, doWhileTest, function (err) { }); -async.doUntil(whileFn, doWhileTest, function (err) { }); -async.during(function (testCallback) { testCallback(new Error(), false); }, function (callback) { callback() }, function (error) { console.log(error) }); -async.doDuring(function (callback) { callback() }, function (testCallback) { testCallback(new Error(), false); }, function (error) { console.log(error) }); -async.forever(function (errBack) { - errBack(new Error("Not going on forever.")); -}, - function (error) { - console.log(error); - } -); +let count = 0; +async.whilst(whileTest, whileFn, err => { }); +async.until(whileTest, whileFn, err => { }); +async.doWhilst(whileFn, doWhileTest, err => { }); +async.doUntil(whileFn, doWhileTest, err => { }); + +async.during(testCallback => { testCallback(new Error(), false); }, callback => { callback(); }, error => { console.log(error); }); +async.doDuring(callback => { callback(); }, testCallback => { testCallback(new Error(), false); }, error => { console.log(error); }); +async.forever(errBack => { errBack(new Error("Not going on forever.")); }, error => { console.log(error); }); async.waterfall([ - function (callback: any) { - callback(null, 'one', 'two'); - }, - function (arg1: any, arg2: any, callback: any) { - callback(null, 'three'); - }, - function (arg1: any, callback: any) { - callback(null, 'done'); - } -], function (err, result) { }); + (callback: any) => { callback(null, 'one', 'two'); }, + (arg1: any, arg2: any, callback: any) => { callback(null, 'three'); }, + (arg1: any, callback: any) => { callback(null, 'done'); } + ], + (err, result) => { }); - -var q = async.queue(function (task: any, callback: (err?:Error,msg?:string) => void) { +const q = async.queue((task: any, callback: (err?: Error, msg?: string) => void) => { console.log('hello ' + task.name); - callback(undefined,'a message.'); + callback(undefined, 'a message.'); }, 2); - -q.drain = function () { - console.log('all items have been processed'); -} +q.drain = () => { console.log('all items have been processed'); }; q.push({ name: 'foo' }); - -q.push({ name: 'bar' }, function (err) { - console.log('finished processing bar'); -}); - -q.push([{ name: 'baz' }, { name: 'bay' }, { name: 'bax' }], function (err) { - console.log('finished processing bar'); -}); - -q.push({name: 'foo'}, function (err, msg) { - console.log('foo finished with a message "'+ msg! + '"'); -}); +q.push({ name: 'bar' }, err => { console.log('finished processing bar'); }); +q.push([{ name: 'baz' }, { name: 'bay' }, { name: 'bax' }], err => { console.log('finished processing bar'); }); +q.push({name: 'foo'}, (err, msg) => { console.log(`foo finished with a message "${msg!}"`); }); q.unshift({ name: 'foo' }); +q.unshift({ name: 'bar' }, err => { console.log('finished processing bar'); }); +q.unshift([{ name: 'baz' }, { name: 'bay' }, { name: 'bax' }], err => { console.log('finished processing bar'); }); -q.unshift({ name: 'bar' }, function (err) { - console.log('finished processing bar'); -}); +const qLength: number = q.length(); +const qStarted: boolean = q.started; +const qPaused: boolean = q.paused; +const qProcessingCount: number = q.running(); +const qIsIdle: boolean = q.idle(); -q.unshift([{ name: 'baz' }, { name: 'bay' }, { name: 'bax' }], function (err) { - console.log('finished processing bar'); -}); +q.saturated = () => { console.log('queue is saturated.'); }; -var qLength : number = q.length(); -var qStarted : boolean = q.started; -var qPaused : boolean = q.paused; -var qProcessingCount : number = q.running(); -var qIsIdle : boolean = q.idle(); +q.empty = () => { console.log('queue is empty.'); }; -q.saturated = function() { - console.log('queue is saturated.'); -} - -q.empty = function() { - console.log('queue is empty.'); -} - -q.drain = function() { - console.log('queue was drained.'); -} +q.drain = () => { console.log('queue was drained.'); }; q.pause(); q.resume(); q.kill(); // tests for strongly typed tasks -var q2 = async.queue(function (task: string, callback: () => void) { +const q2 = async.queue((task: string, callback: () => void) => { console.log('Task: ' + task); callback(); }, 1); q2.push('task1'); - -q2.push('task2', function (error) { - console.log('Finished tasks'); -}); - -q2.push(['task3', 'task4', 'task5'], function (error) { - console.log('Finished tasks'); -}); +q2.push('task2', error => { console.log('Finished tasks'); }); +q2.push(['task3', 'task4', 'task5'], error => { console.log('Finished tasks'); }); q2.unshift('task1'); +q2.unshift('task2', error => { console.log('Finished tasks'); }); +q2.unshift(['task3', 'task4', 'task5'], error => { console.log('Finished tasks'); }); -q2.unshift('task2', function (error) { - console.log('Finished tasks'); -}); +const q2Length = q2.length(); +q2.push('testRemovalTask'); +q2.remove(x => x.data === 'testTaskRemoval'); +if (q2Length !== q2.length()) { + throw new Error('Failed to remove a task from queue.'); +} -q2.unshift(['task3', 'task4', 'task5'], function (error) { - console.log('Finished tasks'); -}); - - -var aq = async.queue(function (level: number, callback: (error?: Error, newLevel?: number) => void) { +const aq = async.queue((level: number, callback: (error?: Error, newLevel?: number) => void) => { console.log('hello ' + level); - callback(undefined, level+1); + callback(undefined, level + 1); }); -aq.push(1, function (err : Error, newLevel : number) { +aq.push(1, (err: Error, newLevel: number) => { console.log('finished processing bar' + newLevel); }); // create a cargo object with payload 2 -var cargo = async.cargo(function (tasks, callback) { - for (var i = 0; i < tasks.length; i++) { - console.log('hello ' + tasks[i].name); +const cargo = async.cargo((tasks, callback) => { + for (const task of tasks) { + console.log('hello ' + task.name); } callback(); }, 2); - // add some items -cargo.push({ name: 'foo' }, function (err: Error) { - console.log('finished processing foo'); -}); -cargo.push({ name: 'bar' }, function (err: Error) { - console.log('finished processing bar'); -}); -cargo.push({ name: 'baz' }, function (err: Error) { - console.log('finished processing baz'); -}); +cargo.push({ name: 'foo' }, (err: Error) => { console.log('finished processing foo'); }); +cargo.push({ name: 'bar' }, (err: Error) => { console.log('finished processing bar'); }); +cargo.push({ name: 'baz' }, (err: Error) => { console.log('finished processing baz'); }); -var filename = ''; +const filename = ''; async.auto({ - get_data: function (callback: AsyncResultCallback) { }, - make_folder: function (callback: AsyncResultCallback) { }, - //arrays with different types are not accepted by TypeScript. - write_file: ['get_data', 'make_folder', function (callback: AsyncResultCallback) { + get_data: (callback: AsyncResultCallback) => { }, + make_folder: (callback: AsyncResultCallback) => { }, + + // arrays with different types are not accepted by TypeScript. + write_file: ['get_data', 'make_folder', ((callback: AsyncResultCallback) => { callback(null, filename); - } as any], - //arrays with different types are not accepted by TypeScript. - email_link: ['write_file', function (callback: AsyncResultCallback, results: any) { } as any] + }) as any], + + // arrays with different types are not accepted by TypeScript. + email_link: ['write_file', ((callback: AsyncResultCallback, results: any) => { }) as any] }); async.auto({ - get_data: function (callback: AsyncResultCallback) { }, - make_folder: function (callback: AsyncResultCallback) { }, - //arrays with different types are not accepted by TypeScript. - write_file: ['get_data', 'make_folder', function (callback: AsyncResultCallback) { - callback(null, filename); - } as any], - //arrays with different types are not accepted by TypeScript. - email_link: ['write_file', function (callback: AsyncResultCallback, results: any) { } as any] -}, function (err, results) { - console.log('finished auto'); -}); + get_data: (callback: AsyncResultCallback) => { }, + make_folder: (callback: AsyncResultCallback) => { }, + + // arrays with different types are not accepted by TypeScript. + write_file: ['get_data', 'make_folder', ((callback: AsyncResultCallback) => { callback(null, filename); }) as any], + + // arrays with different types are not accepted by TypeScript. + email_link: ['write_file', ((callback: AsyncResultCallback, results: any) => { }) as any] + }, + (err, results) => { console.log('finished auto'); } +); interface A { get_data: any; @@ -418,32 +284,28 @@ interface A { } async.auto({ - get_data: function (callback: AsyncResultCallback) { }, - make_folder: function (callback: AsyncResultCallback) { }, - //arrays with different types are not accepted by TypeScript. - write_file: ['get_data', 'make_folder', function (callback: AsyncResultCallback) { - callback(null, filename); - } as any], - //arrays with different types are not accepted by TypeScript. - email_link: ['write_file', function (callback: AsyncResultCallback, results: any) { } as any] -}, 1, function (err, results) { - console.log('finished auto'); -}); + get_data: (callback: AsyncResultCallback) => { }, + make_folder: (callback: AsyncResultCallback) => { }, -async.retry(3, function (callback, results) { }, function (err, result) { }); -async.retry({ times: 3, interval: 200 }, function (callback, results) { }, function (err, result) { }); -async.retry({ times: 3, interval: (retryCount) => { return 200 * retryCount; } }, function (callback, results) { }, function (err, result) { }); + // arrays with different types are not accepted by TypeScript. + write_file: ['get_data', 'make_folder', ((callback: AsyncResultCallback) => { callback(null, filename); }) as any], + // arrays with different types are not accepted by TypeScript. + email_link: ['write_file', ((callback: AsyncResultCallback, results: any) => { }) as any] + }, + 1, + (err, results) => { console.log('finished auto'); } +); + +async.retry(3, (callback, results) => { }, (err, result) => { }); +async.retry({ times: 3, interval: 200 }, (callback, results) => { }, (err, result) => { }); +async.retry({ times: 3, interval: (retryCount) => 200 * retryCount }, (callback, results) => { }, (err, result) => { }); async.parallel([ - function (callback: ( err:Error, val:string ) => void ) { }, - function (callback) { } -], -function (err:Error,results:Array) { - async.series([ - function (callback) { }, - function email_link(callback) { } - ]); + (callback: (err: Error, val: string) => void) => { }, + callback => { } + ], + (err: Error, results: string[]) => { async.series([callback => { }, function email_link(callback) { }]); }); async.parallel([ @@ -451,428 +313,281 @@ async.parallel([ async.apply(fs.writeFile, 'testfile2', 'test2'), ]); - async.parallel([ - function (callback) { - fs.writeFile('testfile1', 'test1', callback); - }, - function (callback) { - fs.writeFile('testfile2', 'test2', callback); - }, + callback => { fs.writeFile('testfile1', 'test1', callback); }, + callback => { fs.writeFile('testfile2', 'test2', callback); } ]); -var call_order: string[] = []; -async.nextTick(function () { - call_order.push('two'); -}); +const call_order: string[] = []; +async.nextTick(() => { call_order.push('two'); }); call_order.push('one'); -var slow_fn = function (name: string, callback: any) { - callback(null, 123); -}; -var fn = async.memoize(slow_fn); -fn('some name', function () {}); +const slow_fn = (name: string, callback: any) => { callback(null, 123); }; +const fn = async.memoize(slow_fn); + +fn('some name', () => { }); async.unmemoize(fn); -async.ensureAsync(function () { }); +async.ensureAsync(() => { }); async.constant(42); -async.asyncify(function () { }); +async.asyncify(() => { }); -async.log(function (name: any, callback: any) { - setTimeout(function () { - callback(null, 'hello ' + name); - }, 0); -}, "world" - ); +async.log( + (name: any, callback: any) => { setTimeout(() => { callback(null, 'hello ' + name); }, 0); }, + "world"); -async.dir(function (name: string, callback: any) { - setTimeout(function () { - callback(null, { hello: name }); - }, 1000); -}, "world"); +async.dir((name: string, callback: any) => { setTimeout(() => { callback(null, { hello: name }); }, 1000); }, "world"); // each -async.each({ - "a": 1, - "b": 2 -}, function(val: number, next: ErrorCallback): void { +async.each( + { a: 1, b: 2 }, + (val: number, next: ErrorCallback) => { + setTimeout(() => { + console.log(`async.each: ${val}`); + next(); + }, + 500); + }, + (err?: Error) => { console.log("async.each: done."); } +); - setTimeout(function(): void { +async.eachSeries( + { a: 1, b: 2 }, + (val: number, next: ErrorCallback) => { + setTimeout( + () => { + console.log(`async.eachSeries: ${val}`); + next(); + }, + 500); + }, + (err?: Error) => { console.log("async.eachSeries: done."); } +); - console.log(`async.each: ${val}`); - - next(); - - }, 500); - -}, function(err?: Error): void { - - console.log("async.each: done."); - -}); - -async.eachSeries({ - "a": 1, - "b": 2 -}, function(val: number, next: ErrorCallback): void { - - setTimeout(function(): void { - - console.log(`async.eachSeries: ${val}`); - - next(); - - }, 500); - -}, function(err?: Error): void { - - console.log("async.eachSeries: done."); - -}); - -async.eachLimit({ - "a": 1, - "b": 2, - "c": 3, - "d": 4, - "e": 5, - "f": 6 -}, 2, function(val: number, next: ErrorCallback): void { - - setTimeout(function(): void { - - console.log(`async.eachLimit: ${val}`); - - next(); - - }, 500); - -}, function(err?: Error): void { - - console.log("async.eachLimit: done."); - -}); +async.eachLimit( + { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }, + 2, + (val: number, next: ErrorCallback) => { + setTimeout(() => { + console.log(`async.eachLimit: ${val}`); + next(); + }, + 500); + }, + (err?: Error) => { console.log("async.eachLimit: done."); } +); // forEachOf/eachOf -async.eachOf({ - "a": 1, - "b": 2 -}, function(val: number, key: string, next: ErrorCallback): void { +async.eachOf( + { a: 1, b: 2 }, + (val: number, key: string, next: ErrorCallback) => { + setTimeout( + () => { + console.log(`async.forEachOf/eachOf: ${key} = ${val}`); + next(); + }, + 500); + }, + (err?: Error) => { console.log("async.forEachOf/eachOf: done."); } +); - setTimeout(function(): void { +async.forEachOfSeries( + { a: 1, b: 2 }, + (val: number, key: string, next: ErrorCallback) => { + setTimeout( + () => { + console.log(`async.forEachOfSeries: ${key} = ${val}`); + next(); + }, + 500); + }, + (err?: Error) => { console.log("async.forEachOfSeries: done."); } +); - console.log(`async.forEachOf/eachOf: ${key} = ${val}`); - - next(); - - }, 500); - -}, function(err?: Error): void { - - console.log("async.forEachOf/eachOf: done."); - -}); - -async.forEachOfSeries({ - "a": 1, - "b": 2 -}, function(val: number, key: string, next: ErrorCallback): void { - - setTimeout(function(): void { - - console.log(`async.forEachOfSeries: ${key} = ${val}`); - - next(); - - }, 500); - -}, function(err?: Error): void { - - console.log("async.forEachOfSeries: done."); - -}); - -async.forEachOfLimit({ - "a": 1, - "b": 2, - "c": 3, - "d": 4, - "e": 5, - "f": 6 -}, 2, function(val: number, key: string, next: ErrorCallback): void { - - setTimeout(function(): void { - - console.log(`async.forEachOfLimit: ${key} = ${val}`); - - next(); - - }, 500); - -}, function(err?: Error): void { - - console.log("async.forEachOfLimit: done."); - -}); +async.forEachOfLimit( + { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }, + 2, + (val: number, key: string, next: ErrorCallback) => { + setTimeout( + () => { + console.log(`async.forEachOfLimit: ${key} = ${val}`); + next(); + }, + 500); + }, + (err?: Error) => { console.log("async.forEachOfLimit: done."); } +); // map -async.map({ - "a": 1, - "b": 2, - "c": 3 -}, function(val: number, next: AsyncResultCallback): void { +async.map( + { a: 1, b: 2, c: 3 }, + (val: number, next: AsyncResultCallback) => { + setTimeout( + () => { + console.log(`async.map: ${val}`); + next(undefined as any, val.toString()); + }, + 500); + }, + (err: Error, results: string[]) => { console.log("async.map: done with results", results); } +); - setTimeout(function(): void { +async.mapSeries( + { a: 1, b: 2, c: 3 }, + (val: number, next: AsyncResultCallback) => { + setTimeout( + () => { + console.log(`async.mapSeries: ${val}`); + next(undefined as any, val.toString()); + }, + 500); + }, + (err: Error, results: string[]) => { console.log("async.mapSeries: done with results", results); } +); - console.log(`async.map: ${val}`); - - next(undefined as any, val.toString()); - - }, 500); - -}, function(err: Error, results: string[]): void { - - console.log("async.map: done with results", results); - -}); - -async.mapSeries({ - "a": 1, - "b": 2, - "c": 3 -}, function(val: number, next: AsyncResultCallback): void { - - setTimeout(function(): void { - - console.log(`async.mapSeries: ${val}`); - - next(undefined as any, val.toString()); - - }, 500); - -}, function(err: Error, results: string[]): void { - - console.log("async.mapSeries: done with results", results); - -}); - -async.mapLimit({ - "a": 1, - "b": 2, - "c": 3, - "d": 4, - "e": 5, - "f": 6 -}, 2, function(val: number, next: AsyncResultCallback): void { - - setTimeout(function(): void { - - console.log(`async.mapLimit: ${val}`); - - next(undefined as any, val.toString()); - - }, 500); - -}, function(err: Error, results: string[]): void { - - console.log("async.mapLimit: done with results", results); - -}); +async.mapLimit( + { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }, + 2, + (val: number, next: AsyncResultCallback) => { + setTimeout( + () => { + console.log(`async.mapLimit: ${val}`); + next(undefined as any, val.toString()); + }, + 500); + }, + (err: Error, results: string[]) => { console.log("async.mapLimit: done with results", results); } +); // mapValues -async.mapValues({ - "a": 1, - "b": 2, - "c": 3 -}, function(val: number, key: string, next: AsyncResultCallback): void { +async.mapValues( + { a: 1, b: 2, c: 3 }, + (val: number, key: string, next: AsyncResultCallback) => { + setTimeout( + () => { + console.log(`async.mapValues: ${key} = ${val}`); + next(undefined as any, val.toString()); + }, + 500); + }, + (err: Error, results: Dictionary) => { console.log("async.mapValues: done with results", results); } +); - setTimeout(function(): void { - - console.log(`async.mapValues: ${key} = ${val}`); - - next(undefined as any, val.toString()); - - }, 500); - -}, function(err: Error, results: Dictionary): void { - - console.log("async.mapValues: done with results", results); - -}); - -async.mapValuesSeries({ - "a": 1, - "b": 2, - "c": 3 -}, function(val: number, key: string, next: AsyncResultCallback): void { - - setTimeout(function(): void { - - console.log(`async.mapValuesSeries: ${key} = ${val}`); - - next(undefined as any, val.toString()); - - }, 500); - -}, function(err: Error, results: Dictionary): void { - - console.log("async.mapValuesSeries: done with results", results); - -}); +async.mapValuesSeries( + { a: 1, b: 2, c: 3 }, + (val: number, key: string, next: AsyncResultCallback) => { + setTimeout( + () => { + console.log(`async.mapValuesSeries: ${key} = ${val}`); + next(undefined as any, val.toString()); + }, + 500); + }, + (err: Error, results: Dictionary) => { console.log("async.mapValuesSeries: done with results", results); } +); // filter/select/reject -async.filter({ - "a": 1, - "b": 2, - "c": 3 -}, function(val: number, next: AsyncBooleanResultCallback): void { +async.filter( + { a: 1, b: 2, c: 3 }, + (val: number, next: AsyncBooleanResultCallback) => { + setTimeout( + () => { + console.log(`async.filter/select: ${val}`); + next(undefined as any, val % 2 === 0); + }, + 500); + }, + (err: Error, results: number[]) => { console.log("async.filter/select: done with results", results); } +); - setTimeout(function(): void { - - console.log(`async.filter/select: ${val}`); - - next(undefined as any, val % 2 === 0); - - }, 500); - -}, function(err: Error, results: number[]): void { - - console.log("async.filter/select: done with results", results); - -}); - -async.reject({ - "a": 1, - "b": 2, - "c": 3 -}, function(val: number, next: AsyncBooleanResultCallback): void { - - setTimeout(function(): void { - - console.log(`async.reject: ${val}`); - - next(undefined as any, val % 2 === 0); - - }, 500); - -}, function(err: Error, results: number[]): void { - - console.log("async.reject: done with results", results); - -}); +async.reject( + { a: 1, b: 2, c: 3 }, + (val: number, next: AsyncBooleanResultCallback) => { + setTimeout( + () => { + console.log(`async.reject: ${val}`); + next(undefined as any, val % 2 === 0); + }, + 500); + }, + (err: Error, results: number[]) => { console.log("async.reject: done with results", results); } +); // concat -async.concat({ - "a": "1", - "b": "2", - "c": "3" -}, function(item: string, next: AsyncResultCallback): void { - - console.log(`async.concat: ${item}`); - - next(undefined as any, [item, item, item]); - -}, function(err: Error, results: string[]) { - - console.log("async.concat: done with results", results); - -}); +async.concat( + { a: "1", b: "2", c: "3" }, + (item: string, next: AsyncResultCallback) => { + console.log(`async.concat: ${item}`); + next(undefined as any, [item, item, item]); + }, + (err: Error, results: string[]) => { console.log("async.concat: done with results", results); } +); // detect/find -async.detect({ - "a": 1, - "b": 2, - "c": 3 -}, function(item: number, next: AsyncBooleanResultCallback): void { - - console.log(`async.detect/find: ${item}`); - - next(undefined as any, item > 1); - -}, function(err: Error, result: number) { - - if (err) { - - console.log(err); - - } else { - - console.log("async.detect/find: done with result", result); +async.detect( + { a: 1, b: 2, c: 3 }, + (item: number, next: AsyncBooleanResultCallback) => { + console.log(`async.detect/find: ${item}`); + next(undefined as any, item > 1); + }, + (err: Error, result: number) => { + if (err) { + console.log(err); + } else { + console.log("async.detect/find: done with result", result); + } } - -}); +); // every/all -async.every({ - "a": 1, - "b": 2, - "c": 3 -}, function(item: number, next: AsyncBooleanResultCallback): void { - - console.log(`async.every/all: ${item}`); - - next(undefined as any, item > 0); - -}, function(err: Error, result: boolean) { - - console.log("async.every/all: done with result", result); - -}); +async.every( + { a: 1, b: 2, c: 3 }, + (item: number, next: AsyncBooleanResultCallback) => { + console.log(`async.every/all: ${item}`); + next(undefined as any, item > 0); + }, + (err: Error, result: boolean) => { console.log("async.every/all: done with result", result); } +); // some/any -async.some({ - "a": 1, - "b": 2, - "c": 3 -}, function(item: number, next: AsyncBooleanResultCallback): void { - - console.log(`async.some/any: ${item}`); - - next(undefined as any, item > 2); - -}, function(err: Error, result: boolean) { - - console.log("async.some/any: done with result", result); - -}); +async.some( + { a: 1, b: 2, c: 3 }, + (item: number, next: AsyncBooleanResultCallback) => { + console.log(`async.some/any: ${item}`); + next(undefined as any, item > 2); + }, + (err: Error, result: boolean) => { console.log("async.some/any: done with result", result); } +); // timeout -function myFunction1(foo : any, callback: (err?: Error, result?: any) => void ) : void { +function myFunction1(foo: any, callback: (err?: Error, result?: any) => void): void { console.log(`async.timeout 1 ${foo}`); - return callback(undefined, foo); + callback(undefined, foo); } -var wrapped1 = async.timeout(myFunction1, 1000); -wrapped1({ bar: 'bar' }, function(err : Error, data : any) { - console.log(`async.timeout 1 end ${data}`); -}); +const wrapped1 = async.timeout(myFunction1, 1000); +wrapped1({ bar: 'bar' }, (err: Error, data: any) => { console.log(`async.timeout 1 end ${data}`); }); - -function myFunction2(callback: (err?: Error, result?: any) => void ) : void { +function myFunction2(callback: (err?: Error, result?: any) => void): void { console.log(`async.timeout 2`); - return callback(undefined, { bar: 'bar' }); + callback(undefined, { bar: 'bar' }); } -var wrapped2 = async.timeout(myFunction2, 1000); -wrapped2( function(err : Error, data : any) { - console.log(`async.timeout 2 end ${data}`); -}); +const wrapped2 = async.timeout(myFunction2, 1000); +wrapped2((err: Error, data: any) => { console.log(`async.timeout 2 end ${data}`); }); -function myFunction3(callback: (err?: Error, result?: any) => void ) : void { +function myFunction3(callback: (err?: Error, result?: any) => void): void { console.log(`async.timeout 3`); - return callback(undefined, { bar: 'bar' }); + callback(undefined, { bar: 'bar' }); } -var wrapped3 = async.timeout(myFunction3, 1000, { bar: 'bar' }); -wrapped3( function(err : Error, data : any) { - console.log(`async.timeout 3 end ${data}`); -}); - +const wrapped3 = async.timeout(myFunction3, 1000, { bar: 'bar' }); +wrapped3((err: Error, data: any) => { console.log(`async.timeout 3 end ${data}`); }); diff --git a/types/async/tslint.json b/types/async/tslint.json index 9380375afa..5612ed6657 100644 --- a/types/async/tslint.json +++ b/types/async/tslint.json @@ -1,34 +1,8 @@ { "extends": "dtslint/dt.json", "rules": { - // TODOs - "arrow-return-shorthand": false, - "array-type": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "max-line-length": false, - "no-consecutive-blank-lines": false, - "no-padding": false, - "no-unnecessary-generics": false, - "no-var-keyword": false, - "no-void-expression": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-const": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "trim-file": false, - "typedef-whitespace": false, - "unified-signatures": false, - "whitespace": false + "ban-types": true, // PRODUCES ERRORS WHEN REMOVED + "callable-types": false, // HAS ISSUES + "no-unnecessary-generics": false // HAS ISSUES } }