mirror of
https://github.com/titanscouting/tra-analysis.git
synced 2025-07-28 05:18:50 +00:00
apps
data analysis
website
functions
node_modules
.bin
@firebase
@google-cloud
@grpc
@mrmlnc
@nodelib
@protobufjs
@types
accepts
acorn
acorn-es7-plugin
ajv
ansi-regex
arr-diff
arr-flatten
arr-union
array-filter
array-flatten
array-union
array-uniq
array-unique
arrify
ascli
asn1
assert-plus
assign-symbols
async
dist
internal
CHANGELOG.md
LICENSE
README.md
all.js
allLimit.js
allSeries.js
any.js
anyLimit.js
anySeries.js
apply.js
applyEach.js
applyEachSeries.js
asyncify.js
auto.js
autoInject.js
bower.json
cargo.js
compose.js
concat.js
concatLimit.js
concatSeries.js
constant.js
detect.js
detectLimit.js
detectSeries.js
dir.js
doDuring.js
doUntil.js
doWhilst.js
during.js
each.js
eachLimit.js
eachOf.js
eachOfLimit.js
eachOfSeries.js
eachSeries.js
ensureAsync.js
every.js
everyLimit.js
everySeries.js
filter.js
filterLimit.js
filterSeries.js
find.js
findLimit.js
findSeries.js
foldl.js
foldr.js
forEach.js
forEachLimit.js
forEachOf.js
forEachOfLimit.js
forEachOfSeries.js
forEachSeries.js
forever.js
groupBy.js
groupByLimit.js
groupBySeries.js
index.js
inject.js
log.js
map.js
mapLimit.js
mapSeries.js
mapValues.js
mapValuesLimit.js
mapValuesSeries.js
memoize.js
nextTick.js
package.json
parallel.js
parallelLimit.js
priorityQueue.js
queue.js
race.js
reduce.js
reduceRight.js
reflect.js
reflectAll.js
reject.js
rejectLimit.js
rejectSeries.js
retry.js
retryable.js
select.js
selectLimit.js
selectSeries.js
seq.js
series.js
setImmediate.js
some.js
someLimit.js
someSeries.js
sortBy.js
timeout.js
times.js
timesLimit.js
timesSeries.js
transform.js
tryEach.js
unmemoize.js
until.js
waterfall.js
whilst.js
wrapSync.js
asynckit
atob
aws-sign2
aws4
axios
balanced-match
base
bcrypt-pbkdf
body-parser
brace-expansion
braces
buffer-equal-constant-time
buffer-from
bun
bytebuffer
bytes
cache-base
call-me-maybe
call-signature
camelcase
capture-stack-trace
caseless
class-utils
cliui
code-point-at
collection-visit
colour
combined-stream
component-emitter
compressible
concat-map
concat-stream
configstore
content-disposition
content-type
cookie
cookie-signature
copy-descriptor
core-js
core-util-is
cors
create-error-class
crypto-random-string
dashdash
debug
decamelize
decode-uri-component
deep-equal
define-properties
define-property
delayed-stream
depd
destroy
diff-match-patch
dir-glob
dom-storage
dot-prop
duplexify
eastasianwidth
ecc-jsbn
ecdsa-sig-formatter
ee-first
empower
empower-core
encodeurl
end-of-stream
ent
escape-html
espurify
estraverse
etag
expand-brackets
express
extend
extend-shallow
extglob
extsprintf
fast-deep-equal
fast-glob
fast-json-stable-stringify
faye-websocket
fill-range
finalhandler
firebase-admin
firebase-functions
follow-redirects
for-in
forever-agent
form-data
forwarded
fragment-cache
fresh
fs.realpath
functional-red-black-tree
gcp-metadata
gcs-resumable-upload
get-value
getpass
glob
glob-parent
glob-to-regexp
globby
google-auth-library
google-auto-auth
google-gax
google-p12-pem
google-proto-files
graceful-fs
grpc
gtoken
har-schema
har-validator
has-value
has-values
hash-stream-validation
http-errors
http-parser-js
http-signature
iconv-lite
ignore
imurmurhash
indexof
inflight
inherits
invert-kv
ipaddr.js
is
is-accessor-descriptor
is-buffer
is-data-descriptor
is-descriptor
is-extendable
is-extglob
is-fullwidth-code-point
is-glob
is-number
is-obj
is-plain-object
is-stream-ended
is-typedarray
is-windows
isarray
isobject
isstream
jsbn
json-schema
json-schema-traverse
json-stringify-safe
jsonwebtoken
jsprim
jwa
jws
kind-of
lcid
lodash
lodash.camelcase
lodash.clone
lodash.includes
lodash.isboolean
lodash.isinteger
lodash.isnumber
lodash.isplainobject
lodash.isstring
lodash.merge
lodash.once
log-driver
long
lru-cache
make-dir
map-cache
map-visit
media-typer
merge-descriptors
merge2
methmeth
methods
micromatch
mime
mime-db
mime-types
minimatch
mixin-deep
modelo
ms
nan
nanomatch
negotiator
node-forge
number-is-nan
oauth-sign
object-assign
object-copy
object-keys
object-visit
object.pick
on-finished
once
optjs
os-locale
parseurl
pascalcase
path-dirname
path-is-absolute
path-to-regexp
path-type
performance-now
pify
posix-character-classes
power-assert
power-assert-context-formatter
power-assert-context-reducer-ast
power-assert-context-traversal
power-assert-formatter
power-assert-renderer-assertion
power-assert-renderer-base
power-assert-renderer-comparison
power-assert-renderer-diagram
power-assert-renderer-file
power-assert-util-string-width
process-nextick-args
protobufjs
proxy-addr
pseudomap
psl
pump
pumpify
punycode
qs
range-parser
raw-body
readable-stream
regex-not
repeat-element
repeat-string
request
resolve-url
ret
retry-axios
retry-request
safe-buffer
safe-regex
safer-buffer
send
serve-static
set-value
setprototypeof
signal-exit
slash
snakeize
snapdragon
snapdragon-node
snapdragon-util
source-map
source-map-resolve
source-map-url
split-array-stream
split-string
sshpk
static-extend
statuses
stream-events
stream-shift
string-format-obj
string-width
string_decoder
stringifier
strip-ansi
stubs
through2
to-object-path
to-regex
to-regex-range
tough-cookie
traverse
tslib
tunnel-agent
tweetnacl
type-is
type-name
typedarray
union-value
unique-string
universal-deep-strict-equal
unpipe
unset-value
uri-js
urix
use
util-deprecate
utils-merge
uuid
vary
verror
websocket-driver
websocket-extensions
window-size
wrap-ansi
wrappy
write-file-atomic
xdg-basedir
xmlhttprequest
xtend
y18n
yallist
yargs
index.js
package-lock.json
package.json
node_modules
public
.firebaserc
.gitignore
.runtimeconfig.json
firebase.json
firestore.indexes.json
firestore.rules
package-lock.json
.gitattributes
.gitignore
289 lines
9.6 KiB
JavaScript
289 lines
9.6 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
exports.default = function (tasks, concurrency, callback) {
|
|
if (typeof concurrency === 'function') {
|
|
// concurrency is optional, shift the args.
|
|
callback = concurrency;
|
|
concurrency = null;
|
|
}
|
|
callback = (0, _once2.default)(callback || _noop2.default);
|
|
var keys = (0, _keys2.default)(tasks);
|
|
var numTasks = keys.length;
|
|
if (!numTasks) {
|
|
return callback(null);
|
|
}
|
|
if (!concurrency) {
|
|
concurrency = numTasks;
|
|
}
|
|
|
|
var results = {};
|
|
var runningTasks = 0;
|
|
var hasError = false;
|
|
|
|
var listeners = Object.create(null);
|
|
|
|
var readyTasks = [];
|
|
|
|
// for cycle detection:
|
|
var readyToCheck = []; // tasks that have been identified as reachable
|
|
// without the possibility of returning to an ancestor task
|
|
var uncheckedDependencies = {};
|
|
|
|
(0, _baseForOwn2.default)(tasks, function (task, key) {
|
|
if (!(0, _isArray2.default)(task)) {
|
|
// no dependencies
|
|
enqueueTask(key, [task]);
|
|
readyToCheck.push(key);
|
|
return;
|
|
}
|
|
|
|
var dependencies = task.slice(0, task.length - 1);
|
|
var remainingDependencies = dependencies.length;
|
|
if (remainingDependencies === 0) {
|
|
enqueueTask(key, task);
|
|
readyToCheck.push(key);
|
|
return;
|
|
}
|
|
uncheckedDependencies[key] = remainingDependencies;
|
|
|
|
(0, _arrayEach2.default)(dependencies, function (dependencyName) {
|
|
if (!tasks[dependencyName]) {
|
|
throw new Error('async.auto task `' + key + '` has a non-existent dependency `' + dependencyName + '` in ' + dependencies.join(', '));
|
|
}
|
|
addListener(dependencyName, function () {
|
|
remainingDependencies--;
|
|
if (remainingDependencies === 0) {
|
|
enqueueTask(key, task);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
checkForDeadlocks();
|
|
processQueue();
|
|
|
|
function enqueueTask(key, task) {
|
|
readyTasks.push(function () {
|
|
runTask(key, task);
|
|
});
|
|
}
|
|
|
|
function processQueue() {
|
|
if (readyTasks.length === 0 && runningTasks === 0) {
|
|
return callback(null, results);
|
|
}
|
|
while (readyTasks.length && runningTasks < concurrency) {
|
|
var run = readyTasks.shift();
|
|
run();
|
|
}
|
|
}
|
|
|
|
function addListener(taskName, fn) {
|
|
var taskListeners = listeners[taskName];
|
|
if (!taskListeners) {
|
|
taskListeners = listeners[taskName] = [];
|
|
}
|
|
|
|
taskListeners.push(fn);
|
|
}
|
|
|
|
function taskComplete(taskName) {
|
|
var taskListeners = listeners[taskName] || [];
|
|
(0, _arrayEach2.default)(taskListeners, function (fn) {
|
|
fn();
|
|
});
|
|
processQueue();
|
|
}
|
|
|
|
function runTask(key, task) {
|
|
if (hasError) return;
|
|
|
|
var taskCallback = (0, _onlyOnce2.default)(function (err, result) {
|
|
runningTasks--;
|
|
if (arguments.length > 2) {
|
|
result = (0, _slice2.default)(arguments, 1);
|
|
}
|
|
if (err) {
|
|
var safeResults = {};
|
|
(0, _baseForOwn2.default)(results, function (val, rkey) {
|
|
safeResults[rkey] = val;
|
|
});
|
|
safeResults[key] = result;
|
|
hasError = true;
|
|
listeners = Object.create(null);
|
|
|
|
callback(err, safeResults);
|
|
} else {
|
|
results[key] = result;
|
|
taskComplete(key);
|
|
}
|
|
});
|
|
|
|
runningTasks++;
|
|
var taskFn = (0, _wrapAsync2.default)(task[task.length - 1]);
|
|
if (task.length > 1) {
|
|
taskFn(results, taskCallback);
|
|
} else {
|
|
taskFn(taskCallback);
|
|
}
|
|
}
|
|
|
|
function checkForDeadlocks() {
|
|
// Kahn's algorithm
|
|
// https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm
|
|
// http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html
|
|
var currentTask;
|
|
var counter = 0;
|
|
while (readyToCheck.length) {
|
|
currentTask = readyToCheck.pop();
|
|
counter++;
|
|
(0, _arrayEach2.default)(getDependents(currentTask), function (dependent) {
|
|
if (--uncheckedDependencies[dependent] === 0) {
|
|
readyToCheck.push(dependent);
|
|
}
|
|
});
|
|
}
|
|
|
|
if (counter !== numTasks) {
|
|
throw new Error('async.auto cannot execute tasks due to a recursive dependency');
|
|
}
|
|
}
|
|
|
|
function getDependents(taskName) {
|
|
var result = [];
|
|
(0, _baseForOwn2.default)(tasks, function (task, key) {
|
|
if ((0, _isArray2.default)(task) && (0, _baseIndexOf2.default)(task, taskName, 0) >= 0) {
|
|
result.push(key);
|
|
}
|
|
});
|
|
return result;
|
|
}
|
|
};
|
|
|
|
var _arrayEach = require('lodash/_arrayEach');
|
|
|
|
var _arrayEach2 = _interopRequireDefault(_arrayEach);
|
|
|
|
var _baseForOwn = require('lodash/_baseForOwn');
|
|
|
|
var _baseForOwn2 = _interopRequireDefault(_baseForOwn);
|
|
|
|
var _baseIndexOf = require('lodash/_baseIndexOf');
|
|
|
|
var _baseIndexOf2 = _interopRequireDefault(_baseIndexOf);
|
|
|
|
var _isArray = require('lodash/isArray');
|
|
|
|
var _isArray2 = _interopRequireDefault(_isArray);
|
|
|
|
var _keys = require('lodash/keys');
|
|
|
|
var _keys2 = _interopRequireDefault(_keys);
|
|
|
|
var _noop = require('lodash/noop');
|
|
|
|
var _noop2 = _interopRequireDefault(_noop);
|
|
|
|
var _slice = require('./internal/slice');
|
|
|
|
var _slice2 = _interopRequireDefault(_slice);
|
|
|
|
var _once = require('./internal/once');
|
|
|
|
var _once2 = _interopRequireDefault(_once);
|
|
|
|
var _onlyOnce = require('./internal/onlyOnce');
|
|
|
|
var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
|
|
|
|
var _wrapAsync = require('./internal/wrapAsync');
|
|
|
|
var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
module.exports = exports['default'];
|
|
|
|
/**
|
|
* Determines the best order for running the {@link AsyncFunction}s in `tasks`, based on
|
|
* their requirements. Each function can optionally depend on other functions
|
|
* being completed first, and each function is run as soon as its requirements
|
|
* are satisfied.
|
|
*
|
|
* If any of the {@link AsyncFunction}s pass an error to their callback, the `auto` sequence
|
|
* will stop. Further tasks will not execute (so any other functions depending
|
|
* on it will not run), and the main `callback` is immediately called with the
|
|
* error.
|
|
*
|
|
* {@link AsyncFunction}s also receive an object containing the results of functions which
|
|
* have completed so far as the first argument, if they have dependencies. If a
|
|
* task function has no dependencies, it will only be passed a callback.
|
|
*
|
|
* @name auto
|
|
* @static
|
|
* @memberOf module:ControlFlow
|
|
* @method
|
|
* @category Control Flow
|
|
* @param {Object} tasks - An object. Each of its properties is either a
|
|
* function or an array of requirements, with the {@link AsyncFunction} itself the last item
|
|
* in the array. The object's key of a property serves as the name of the task
|
|
* defined by that property, i.e. can be used when specifying requirements for
|
|
* other tasks. The function receives one or two arguments:
|
|
* * a `results` object, containing the results of the previously executed
|
|
* functions, only passed if the task has any dependencies,
|
|
* * a `callback(err, result)` function, which must be called when finished,
|
|
* passing an `error` (which can be `null`) and the result of the function's
|
|
* execution.
|
|
* @param {number} [concurrency=Infinity] - An optional `integer` for
|
|
* determining the maximum number of tasks that can be run in parallel. By
|
|
* default, as many as possible.
|
|
* @param {Function} [callback] - An optional callback which is called when all
|
|
* the tasks have been completed. It receives the `err` argument if any `tasks`
|
|
* pass an error to their callback. Results are always returned; however, if an
|
|
* error occurs, no further `tasks` will be performed, and the results object
|
|
* will only contain partial results. Invoked with (err, results).
|
|
* @returns undefined
|
|
* @example
|
|
*
|
|
* async.auto({
|
|
* // this function will just be passed a callback
|
|
* readData: async.apply(fs.readFile, 'data.txt', 'utf-8'),
|
|
* showData: ['readData', function(results, cb) {
|
|
* // results.readData is the file's contents
|
|
* // ...
|
|
* }]
|
|
* }, callback);
|
|
*
|
|
* async.auto({
|
|
* get_data: function(callback) {
|
|
* console.log('in get_data');
|
|
* // async code to get some data
|
|
* callback(null, 'data', 'converted to array');
|
|
* },
|
|
* make_folder: function(callback) {
|
|
* console.log('in make_folder');
|
|
* // async code to create a directory to store a file in
|
|
* // this is run at the same time as getting the data
|
|
* callback(null, 'folder');
|
|
* },
|
|
* write_file: ['get_data', 'make_folder', function(results, callback) {
|
|
* console.log('in write_file', JSON.stringify(results));
|
|
* // once there is some data and the directory exists,
|
|
* // write the data to a file in the directory
|
|
* callback(null, 'filename');
|
|
* }],
|
|
* email_link: ['write_file', function(results, callback) {
|
|
* console.log('in email_link', JSON.stringify(results));
|
|
* // once the file is written let's email a link to it...
|
|
* // results.write_file contains the filename returned by write_file.
|
|
* callback(null, {'file':results.write_file, 'email':'user@example.com'});
|
|
* }]
|
|
* }, function(err, results) {
|
|
* console.log('err = ', err);
|
|
* console.log('results = ', results);
|
|
* });
|
|
*/ |