Added definitions and test for node-array-ext.

This commit is contained in:
Beng89 2015-10-26 23:45:30 -05:00
parent 9fb1a50741
commit 2192b79337
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,23 @@
/// <reference path="./node-array-ext.d.ts" />
import extensions = require("node-array-ext");
var array: Array<string> = [ "hello", "world", "test" ];
var result: string = "";
var finish = function(err?: Error) {
if(err) {
console.log(err);
}
else {
console.log(result);
}
}
function each(i: number, element: string, next: (err?: Error) => void): void {
setTimeout(function() {
console.log("%s => %s", i, element);
result += element + " ";
next();
}, 50 * (array.length - i));
}
extensions.asyncEach<string>(array, each, finish);
extensions.awaitEach<string>(array, each, finish);

17
node-array-ext/node-array-ext.d.ts vendored Normal file
View File

@ -0,0 +1,17 @@
// Type definitions for node-array-ext v1.0.00
// Project: https://github.com/Beng89/node-array-ext
// Definitions by: Ben Goltz <https://github.com/Beng89>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "node-array-ext" {
/**
* Processes each of the elements in the array and triggers a callback once every element has been processed.
* - note that the elements are called in order but are not guaranteed to finish in order.
*/
export function asyncEach<T> (array: Array<T>, each: (i: number, element: T, done: (err?: Error) => void) => void, finish: (err?: Error) => void): void;
/**
* Processes each of the elements in the array and triggers a callback once every element has been processed.
* - note that the elements are called in order and are guaranteed to finish in order.
*/
export function awaitEach<T> (array: Array<T>, each: (i: number, element: T, done: (err?: Error) => void) => void, finish: (err?: Error) => void): void;
}