mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-11 11:50:54 +08:00
Move definitions and test in separate folders
This enables each definition to have a readme if necessary. Also a .json metadata file to help with package managers. And last, to have different versions of the definitions.
This commit is contained in:
Vendored
+74
@@ -0,0 +1,74 @@
|
||||
// Type definitions for Async 0.1
|
||||
// Project: https://github.com/caolan/async
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
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; }
|
||||
|
||||
interface AsyncQueue {
|
||||
length(): number;
|
||||
concurrency: number;
|
||||
push(task: any, callback: AsyncCallback): void;
|
||||
saturated: AsyncCallback;
|
||||
empty: AsyncCallback;
|
||||
drain: AsyncCallback;
|
||||
}
|
||||
|
||||
interface Async {
|
||||
|
||||
// Collections
|
||||
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
|
||||
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
|
||||
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;
|
||||
@@ -0,0 +1,213 @@
|
||||
/// <reference path="../Definitions/async-0.1.d.ts" />
|
||||
|
||||
var fs, path;
|
||||
|
||||
function callback() {}
|
||||
|
||||
async.map(['file1', 'file2', 'file3'], fs.stat, function (err, results) { });
|
||||
|
||||
async.filter(['file1', 'file2', 'file3'], path.exists, function (results) { });
|
||||
|
||||
async.parallel([
|
||||
function () { },
|
||||
function () { }
|
||||
], callback);
|
||||
|
||||
async.series([
|
||||
function () { },
|
||||
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)
|
||||
});
|
||||
}, function (err, result) { });
|
||||
|
||||
async.detect(['file1', 'file2', 'file3'], path.exists, function (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.every(['file1', 'file2', 'file3'], path.exists, function (result) { });
|
||||
|
||||
async.concat(['dir1', 'dir2', 'dir3'], fs.readdir, function (err, files) { });
|
||||
|
||||
async.series([
|
||||
function (callback) {
|
||||
callback(null, 'one');
|
||||
},
|
||||
function (callback) {
|
||||
callback(null, 'two');
|
||||
},
|
||||
],
|
||||
function (err, results) { });
|
||||
|
||||
async.series({
|
||||
one: function (callback) {
|
||||
setTimeout(function () {
|
||||
callback(null, 1);
|
||||
}, 200);
|
||||
},
|
||||
two: function (callback) {
|
||||
setTimeout(function () {
|
||||
callback(null, 2);
|
||||
}, 100);
|
||||
},
|
||||
},
|
||||
function (err, results) { });
|
||||
|
||||
async.parallel([
|
||||
function (callback) {
|
||||
setTimeout(function () {
|
||||
callback(null, 'one');
|
||||
}, 200);
|
||||
},
|
||||
function (callback) {
|
||||
setTimeout(function () {
|
||||
callback(null, 'two');
|
||||
}, 100);
|
||||
},
|
||||
],
|
||||
function (err, results) { });
|
||||
|
||||
|
||||
async.parallel({
|
||||
one: function (callback) {
|
||||
setTimeout(function () {
|
||||
callback(null, 1);
|
||||
}, 200);
|
||||
},
|
||||
two: function (callback) {
|
||||
setTimeout(function () {
|
||||
callback(null, 2);
|
||||
}, 100);
|
||||
},
|
||||
},
|
||||
function (err, results) { });
|
||||
|
||||
|
||||
var count = 0;
|
||||
|
||||
async.whilst(
|
||||
function () { return count < 5; },
|
||||
function (callback) {
|
||||
count++;
|
||||
setTimeout(callback, 1000);
|
||||
},
|
||||
function (err) { }
|
||||
);
|
||||
|
||||
|
||||
async.waterfall([
|
||||
function (callback) {
|
||||
callback(null, 'one', 'two');
|
||||
},
|
||||
function (arg1, arg2, callback) {
|
||||
callback(null, 'three');
|
||||
},
|
||||
function (arg1, callback) {
|
||||
callback(null, 'done');
|
||||
}
|
||||
], function (err, result) { });
|
||||
|
||||
|
||||
var q = async.queue(function (task, callback) {
|
||||
console.log('hello ' + task.name);
|
||||
callback();
|
||||
}, 2);
|
||||
|
||||
|
||||
q.drain = function () {
|
||||
console.log('all items have been processed');
|
||||
}
|
||||
|
||||
q.push({ name: 'foo' }, function (err) {
|
||||
console.log('finished processing 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');
|
||||
});
|
||||
|
||||
|
||||
async.auto({
|
||||
get_data: function (callback) { },
|
||||
make_folder: function (callback) { },
|
||||
write_file: ['get_data', 'make_folder', function (callback) {
|
||||
callback(null, filename);
|
||||
}],
|
||||
email_link: ['write_file', function (callback, results) { }]
|
||||
});
|
||||
|
||||
|
||||
async.parallel([
|
||||
function (callback) { },
|
||||
function (callback) { }
|
||||
],
|
||||
function (results) {
|
||||
async.series([
|
||||
function (callback) { },
|
||||
email_link: function(callback) { }
|
||||
]);
|
||||
});
|
||||
|
||||
var sys;
|
||||
var iterator = async.iterator([
|
||||
function () { sys.p('one'); },
|
||||
function () { sys.p('two'); },
|
||||
function () { sys.p('three'); }
|
||||
]);
|
||||
|
||||
async.parallel([
|
||||
async.apply(fs.writeFile, 'testfile1', 'test1'),
|
||||
async.apply(fs.writeFile, 'testfile2', 'test2'),
|
||||
]);
|
||||
|
||||
|
||||
async.parallel([
|
||||
function (callback) {
|
||||
fs.writeFile('testfile1', 'test1', callback);
|
||||
},
|
||||
function (callback) {
|
||||
fs.writeFile('testfile2', 'test2', callback);
|
||||
},
|
||||
]);
|
||||
|
||||
var call_order = [];
|
||||
async.nextTick(function () {
|
||||
call_order.push('two');
|
||||
});
|
||||
call_order.push('one');
|
||||
|
||||
var slow_fn = function (name, callback) {
|
||||
callback(null, 123);
|
||||
};
|
||||
var fn = async.memoize(slow_fn);
|
||||
fn('some name', function () {});
|
||||
Reference in New Issue
Block a user