mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Async definitions and tests finished
This commit is contained in:
Vendored
+60
-35
@@ -3,46 +3,71 @@
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
declare module async {
|
||||
interface AsyncCallback { (err: string, results: any): any; }
|
||||
interface AsyncIterator { (item, callback: AsyncCallback): void; }
|
||||
interface AsyncMemoIterator { (memo: any, item: any, callback: AsyncCallback): void; }
|
||||
interface AsyncWorker { (task: any, callback: Function): void; }
|
||||
|
||||
export interface Errback { (err: string): any; }
|
||||
interface AsyncQueue {
|
||||
length(): number;
|
||||
concurrency: number;
|
||||
push(task: any, callback: AsyncCallback): void;
|
||||
saturated: AsyncCallback;
|
||||
empty: AsyncCallback;
|
||||
drain: AsyncCallback;
|
||||
}
|
||||
|
||||
interface Async {
|
||||
|
||||
// Collections
|
||||
export function forEach(arr: any[], iterator: (item, callback: Function) => void, callback: Errback): void;
|
||||
export function forEachSeries(arr: any[], iterator: (item, callback: Function) => void , callback: Errback): void;
|
||||
export function forEachLimit(arr, limit, iterator, callback);
|
||||
export function map(arr, iterator, callback);
|
||||
export function mapSeries(arr, iterator, callback);
|
||||
export function filter(arr, iterator, callback);
|
||||
export function filterSeries(arr, iterator, callback);
|
||||
export function reject(arr, iterator, callback);
|
||||
export function rejectSeries(arr, iterator, callback);
|
||||
export function reduce(arr, memo, iterator, callback);
|
||||
export function reduceRight(arr, memo, iterator, callback);
|
||||
export function detect(arr, iterator, callback);
|
||||
export function detectSeries(arr, iterator, callback);
|
||||
export function sortBy(arr, iterator, callback);
|
||||
export function some(arr, iterator, callback);
|
||||
export function every(arr, iterator, callback);
|
||||
export function concat(arr, iterator, callback);
|
||||
export function concatSeries(arr, iterator, callback);
|
||||
forEach(arr: any[], iterator: AsyncIterator, callback: AsyncCallback): void;
|
||||
forEachSeries(arr: any[], iterator: AsyncIterator, callback: AsyncCallback): void;
|
||||
forEachLimit(arr: any[], limit: number, iterator: AsyncIterator, callback: AsyncCallback): void;
|
||||
map(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
mapSeries(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
filter(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
select(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
filterSeries(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
selectSeries(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
reject(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
rejectSeries(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
reduce(arr: any[], memo: any, iterator: AsyncMemoIterator, callback: AsyncCallback);
|
||||
inject(arr: any[], memo: any, iterator: AsyncMemoIterator, callback: AsyncCallback);
|
||||
foldl(arr: any[], memo: any, iterator: AsyncMemoIterator, callback: AsyncCallback);
|
||||
reduceRight(arr: any[], memo: any, iterator: AsyncMemoIterator, callback: AsyncCallback);
|
||||
foldr(arr: any[], memo: any, iterator: AsyncMemoIterator, callback: AsyncCallback);
|
||||
detect(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
detectSeries(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
sortBy(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
some(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
any(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
every(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
all(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
concat(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
concatSeries(arr: any[], iterator: AsyncIterator, callback: AsyncCallback);
|
||||
|
||||
// Control Flow
|
||||
export function series(tasks, callback? );
|
||||
export function parallel(tasks, callback? );
|
||||
export function whilst(test, fn, callback);
|
||||
export function until(test, fn, callback);
|
||||
export function waterfall(tasks, callback? );
|
||||
export function queue(worker, concurrency);
|
||||
export function auto(tasks, callback? );
|
||||
export function iterator(tasks);
|
||||
export function apply(fn, ...arguments: any[]);
|
||||
export function nextTick(callback);
|
||||
series(tasks: any[], callback?: AsyncCallback): void;
|
||||
series(tasks: any, callback?: AsyncCallback): void;
|
||||
parallel(tasks: any[], callback?: AsyncCallback): void;
|
||||
parallel(tasks: any, callback?: AsyncCallback): void;
|
||||
whilst(test: Function, fn: Function, callback: AsyncCallback): void;
|
||||
until(test: Function, fn: Function, callback: AsyncCallback): void;
|
||||
waterfall(tasks: any[], callback?: AsyncCallback): void;
|
||||
waterfall(tasks: any, callback?: AsyncCallback): void;
|
||||
queue(worker: AsyncWorker, concurrency: number): AsyncQueue;
|
||||
//auto(tasks: any[], callback?: AsyncCallback): void;
|
||||
auto(tasks: any, callback?: AsyncCallback): void;
|
||||
iterator(tasks): Function;
|
||||
apply(fn: Function, ...arguments: any[]): void;
|
||||
nextTick(callback: AsyncCallback): void;
|
||||
|
||||
// Utils
|
||||
export function memoize(fn, hasher? );
|
||||
export function unmemoize(fn);
|
||||
export function log(fn, ...arguments: any[]);
|
||||
export function dir(fn, ...arguments: any[]);
|
||||
export function noConflict();
|
||||
memoize(fn: Function, hasher?: Function): Function;
|
||||
unmemoize(fn: Function): Function;
|
||||
log(fn: Function, ...arguments: any[]): void;
|
||||
dir(fn: Function, ...arguments: any[]): void;
|
||||
noConflict(): Async;
|
||||
}
|
||||
|
||||
declare var async: Async;
|
||||
@@ -7,6 +7,7 @@ The project aims to provide *high quality* definitions for the most popular libr
|
||||
|
||||
Complete
|
||||
--------
|
||||
* [async](https://github.com/caolan/async)
|
||||
* [Backbone.js](http://backbonejs.org/)
|
||||
* [Bootstrap](http://twitter.github.com/bootstrap/)
|
||||
* [Express](http://expressjs.com/) (from TypeScript samples)
|
||||
@@ -30,6 +31,7 @@ Complete
|
||||
|
||||
Next
|
||||
----
|
||||
* ember.js
|
||||
* Angular.js
|
||||
* google.visualization
|
||||
* jQuery Mobile
|
||||
@@ -38,9 +40,4 @@ Next
|
||||
* Meteor
|
||||
* PhoneGap
|
||||
* Isotope
|
||||
* ember.js
|
||||
* Zepto
|
||||
|
||||
Node Modules Definitions
|
||||
------------------------
|
||||
https://github.com/soywiz/typescript-node-definitions
|
||||
* Zepto
|
||||
+11
-26
@@ -2,7 +2,7 @@
|
||||
|
||||
var fs, path;
|
||||
|
||||
//import "async";
|
||||
function callback() {}
|
||||
|
||||
async.map(['file1', 'file2', 'file3'], fs.stat, function (err, results) { });
|
||||
|
||||
@@ -18,18 +18,24 @@ async.series([
|
||||
function () { }
|
||||
]);
|
||||
|
||||
var data;
|
||||
function asyncProcess() { }
|
||||
async.map(data, asyncProcess, function (err, results) {
|
||||
alert(results);
|
||||
});
|
||||
|
||||
var openFiles = ['file1', 'file2'];
|
||||
var saveFile = function () { }
|
||||
async.forEach(openFiles, saveFile, function (err) { });
|
||||
|
||||
var documents, requestApi;
|
||||
async.forEachLimit(documents, 20, requestApi, function (err) { });
|
||||
|
||||
async.map(['file1', 'file2', 'file3'], fs.stat, function (err, results) { });
|
||||
|
||||
async.filter(['file1', 'file2', 'file3'], path.exists, function (results) { });
|
||||
|
||||
var process;
|
||||
async.reduce([1, 2, 3], 0, function (memo, item, callback) {
|
||||
process.nextTick(function () {
|
||||
callback(null, memo + item)
|
||||
@@ -60,8 +66,6 @@ async.series([
|
||||
],
|
||||
function (err, results) { });
|
||||
|
||||
|
||||
|
||||
async.series({
|
||||
one: function (callback) {
|
||||
setTimeout(function () {
|
||||
@@ -169,13 +173,12 @@ async.parallel([
|
||||
],
|
||||
function (results) {
|
||||
async.series([
|
||||
function (callback) {
|
||||
},
|
||||
function (callback) { },
|
||||
email_link: function(callback) { }
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
var sys;
|
||||
var iterator = async.iterator([
|
||||
function () { sys.p('one'); },
|
||||
function () { sys.p('two'); },
|
||||
@@ -200,29 +203,11 @@ async.parallel([
|
||||
var call_order = [];
|
||||
async.nextTick(function () {
|
||||
call_order.push('two');
|
||||
// call_order now equals ['one','two]
|
||||
});
|
||||
call_order.push('one');
|
||||
|
||||
|
||||
var slow_fn = function (name, callback) {
|
||||
callback(null, result);
|
||||
callback(null, 123);
|
||||
};
|
||||
var fn = async.memoize(slow_fn);
|
||||
|
||||
// fn can now be used as if it were slow_fn
|
||||
fn('some name', function () {
|
||||
// callback
|
||||
});
|
||||
|
||||
var hello = function (name, callback) {
|
||||
setTimeout(function () {
|
||||
callback(null, 'hello ' + name);
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
var hello = function (name, callback) {
|
||||
setTimeout(function () {
|
||||
callback(null, { hello: name });
|
||||
}, 1000);
|
||||
};
|
||||
fn('some name', function () {});
|
||||
|
||||
Reference in New Issue
Block a user