Add telemetry for TRAP caching
This commit is contained in:
parent
ca10a6d552
commit
4139682b64
63 changed files with 1195 additions and 126 deletions
2
node_modules/tiny-each-async/.npmignore
generated
vendored
Normal file
2
node_modules/tiny-each-async/.npmignore
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
bench/
|
||||
examples/
|
||||
9
node_modules/tiny-each-async/.travis.yml
generated
vendored
Normal file
9
node_modules/tiny-each-async/.travis.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- 'stable'
|
||||
- '0.12'
|
||||
- '0.10'
|
||||
sudo: false
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
52
node_modules/tiny-each-async/README.md
generated
vendored
Normal file
52
node_modules/tiny-each-async/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# tiny-each-async
|
||||
|
||||
Asynchronous iterator function similar to (and inspired by) [async.each](https://github.com/caolan/async#eacharr-iterator-callback), with support for concurrency limit and item index.
|
||||
|
||||
[](http://travis-ci.org/alessioalex/tiny-each-async)
|
||||
|
||||
## Usage
|
||||
|
||||
### each(array, [limit], iterator, [callback])
|
||||
|
||||
Arguments:
|
||||
|
||||
- array - An array of items to iterate through.
|
||||
- [limit] - An (optional) integer for determining how many `iterator` functions should be run in parallel.
|
||||
- iterator(item, [index], callback) - A function to be applied to each item in the array. When it has finished processing the item then the `callback` function should be called (in case of a failure with the `error` argument, otherwise none).
|
||||
- callback(err) - An optional callback function that gets called when either all `iterator` functions have finished or one of them has returned an error.
|
||||
|
||||
### Example
|
||||
|
||||
```js
|
||||
var eachAsync = require('tiny-each-async');
|
||||
var timeouts = [300, 100, 2000];
|
||||
|
||||
eachAsync(['file1', 'file2', 'file3'], function(item, index, next) {
|
||||
setTimeout(function() {
|
||||
console.log(item, index, timeouts[index]);
|
||||
next();
|
||||
}, timeouts[index]);
|
||||
}, function(err) {
|
||||
return err ? console.error(err.stack) : console.log('all done');
|
||||
});
|
||||
```
|
||||
|
||||
For more examples checkout the [/examples](/examples) folder.
|
||||
|
||||
## FAQ
|
||||
|
||||
- Why the name?
|
||||
|
||||
Other possible names were already taken, and the actual source code is tiny.
|
||||
|
||||
- Why create another async library?
|
||||
|
||||
Because doing your own thing is fun.
|
||||
|
||||
- What if my iterator function is sync, but I want it && the callback to be async?
|
||||
|
||||
Then you might want to use [dezalgo](https://github.com/npm/dezalgo).
|
||||
|
||||
## License
|
||||
|
||||
[MIT](http://alessioalex.mit-license.org/)
|
||||
59
node_modules/tiny-each-async/index.js
generated
vendored
Normal file
59
node_modules/tiny-each-async/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* eslint-disable no-use-before-define */
|
||||
'use strict';
|
||||
|
||||
module.exports = function eachAsync(arr, parallelLimit, iteratorFn, cb) {
|
||||
var pending = 0;
|
||||
var index = 0;
|
||||
var lastIndex = arr.length - 1;
|
||||
var called = false;
|
||||
var limit;
|
||||
var callback;
|
||||
var iterate;
|
||||
|
||||
if (typeof parallelLimit === 'number') {
|
||||
limit = parallelLimit;
|
||||
iterate = iteratorFn;
|
||||
callback = cb || function noop() {};
|
||||
} else {
|
||||
iterate = parallelLimit;
|
||||
callback = iteratorFn || function noop() {};
|
||||
limit = arr.length;
|
||||
}
|
||||
|
||||
if (!arr.length) { return callback(); }
|
||||
|
||||
var iteratorLength = iterate.length;
|
||||
|
||||
var shouldCallNextIterator = function shouldCallNextIterator() {
|
||||
return (!called && (pending < limit) && (index < lastIndex));
|
||||
};
|
||||
|
||||
var iteratorCallback = function iteratorCallback(err) {
|
||||
if (called) { return; }
|
||||
|
||||
pending--;
|
||||
|
||||
if (err || (index === lastIndex && !pending)) {
|
||||
called = true;
|
||||
|
||||
callback(err);
|
||||
} else if (shouldCallNextIterator()) {
|
||||
processIterator(++index);
|
||||
}
|
||||
};
|
||||
|
||||
var processIterator = function processIterator() {
|
||||
pending++;
|
||||
|
||||
var args = (iteratorLength === 2) ? [arr[index], iteratorCallback]
|
||||
: [arr[index], index, iteratorCallback];
|
||||
|
||||
iterate.apply(null, args);
|
||||
|
||||
if (shouldCallNextIterator()) {
|
||||
processIterator(++index);
|
||||
}
|
||||
};
|
||||
|
||||
processIterator();
|
||||
};
|
||||
38
node_modules/tiny-each-async/package.json
generated
vendored
Normal file
38
node_modules/tiny-each-async/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "tiny-each-async",
|
||||
"version": "2.0.3",
|
||||
"description": "Asynchronous iterator function for parallel processing.",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"each",
|
||||
"async",
|
||||
"asynchronous",
|
||||
"iteration",
|
||||
"iterate",
|
||||
"loop",
|
||||
"foreach",
|
||||
"parallel",
|
||||
"concurrent",
|
||||
"array",
|
||||
"flow",
|
||||
"control flow"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"alessioalex-standard": "^1.0.0",
|
||||
"async": "^1.5.0",
|
||||
"husky": "^0.10.1",
|
||||
"lolex": "^1.3.2",
|
||||
"matcha": "^0.6.0",
|
||||
"tape": "^4.2.2"
|
||||
},
|
||||
"scripts": {
|
||||
"bench": "matcha bench/*.js",
|
||||
"test": "tape test.js",
|
||||
"lint": "alessioalex-standard",
|
||||
"precommit": "npm run lint && npm test"
|
||||
},
|
||||
"author": "Alexandru Vladutu <alexandru.vladutu@gmail.com>",
|
||||
"license": "MIT",
|
||||
"repository": "alessioalex/tiny-each-async"
|
||||
}
|
||||
95
node_modules/tiny-each-async/test.js
generated
vendored
Normal file
95
node_modules/tiny-each-async/test.js
generated
vendored
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/* eslint-disable no-console, func-names */
|
||||
'use strict';
|
||||
|
||||
var it = require('tape');
|
||||
var eachAsync = require('./');
|
||||
var lolex = require('lolex');
|
||||
|
||||
it('should call back even if the array is empty', function(t) {
|
||||
eachAsync([], function(item, next) {
|
||||
next();
|
||||
}, function() {
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
it('should execute the final callback once all individual tasks are finished', function(t) {
|
||||
var counter = 0;
|
||||
|
||||
eachAsync([1, 2, 3], function(item, next) {
|
||||
counter++;
|
||||
next();
|
||||
}, function() {
|
||||
t.equal(counter, 3);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
it('should provide index as an argument for the iterator if needed', function(t) {
|
||||
var items = [11, 22, 33];
|
||||
|
||||
eachAsync(items, function(item, i, next) {
|
||||
t.equal(item, items[i]);
|
||||
|
||||
next();
|
||||
}, function() {
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
it('should treat iterator index as an optional param', function(t) {
|
||||
eachAsync([1, 2, 3], function(item, next) {
|
||||
next();
|
||||
}, function() {
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
it('should treat limit as an optional param', function(t) {
|
||||
eachAsync([1, 2, 3], function(item, next) {
|
||||
next();
|
||||
}, function() {
|
||||
eachAsync([1, 2, 3], 2, function(item, next) {
|
||||
next();
|
||||
}, function() {
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return early in case there\'s an error', function(t) {
|
||||
var error = new Error('test');
|
||||
|
||||
eachAsync([1, 2, 3], function(item, next) {
|
||||
if (item === 2) { return next(error); }
|
||||
|
||||
t.ok(item === 1);
|
||||
|
||||
next();
|
||||
}, function(err) {
|
||||
t.equal(err, error);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
it('should limit the concurrency', function(t) {
|
||||
var clock = lolex.install();
|
||||
var items = [];
|
||||
|
||||
eachAsync([1, 2, 3, 4, 5], 2, function(item, next) {
|
||||
setTimeout(function() {
|
||||
items.push(item);
|
||||
next();
|
||||
}, 1000);
|
||||
}, function() {
|
||||
clock.uninstall();
|
||||
t.end();
|
||||
});
|
||||
|
||||
clock.tick(1001);
|
||||
t.deepEqual([1, 2], items);
|
||||
clock.tick(1001);
|
||||
t.deepEqual([1, 2, 3, 4], items);
|
||||
clock.tick(1000);
|
||||
t.deepEqual([1, 2, 3, 4, 5], items);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue