mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Added definitions and test for node-array-ext.
This commit is contained in:
parent
9fb1a50741
commit
2192b79337
23
node-array-ext/node-array-ext-tests.ts
Normal file
23
node-array-ext/node-array-ext-tests.ts
Normal 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
17
node-array-ext/node-array-ext.d.ts
vendored
Normal 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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user