passenger 5.0.21 → 5.0.22
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of passenger might be problematic. Click here for more details.
- checksums.yaml +8 -8
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/CHANGELOG +38 -2
- data/CONTRIBUTORS +3 -0
- data/README.md +5 -1
- data/bin/passenger-status +2 -7
- data/build/agent.rb +2 -0
- data/build/cxx_dependency_map.rb +1464 -162
- data/build/node_tests.rb +1 -1
- data/build/packaging.rb +1 -1
- data/dev/ci/run_travis.sh +1 -1
- data/dev/vagrant/provision.sh +1 -1
- data/npm-shrinkwrap.json +635 -125
- data/package.json +1 -1
- data/resources/templates/standalone/config.erb +33 -161
- data/resources/templates/standalone/global.erb +15 -0
- data/resources/templates/standalone/http.erb +40 -0
- data/resources/templates/standalone/mass_deployment_default_server.erb +11 -0
- data/resources/templates/standalone/rails_asset_pipeline.erb +22 -0
- data/resources/templates/standalone/server.erb +58 -0
- data/src/agent/Core/ApiServer.h +37 -32
- data/src/agent/Core/ApplicationPool/BasicGroupInfo.h +1 -1
- data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +6 -0
- data/src/agent/Core/ApplicationPool/Common.h +1 -1
- data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +4 -0
- data/src/agent/Core/ApplicationPool/Implementation.cpp +2 -2
- data/src/agent/Core/ApplicationPool/Options.h +18 -1
- data/src/agent/Core/ApplicationPool/Pool.h +1 -1
- data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +6 -6
- data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +3 -3
- data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +6 -0
- data/src/agent/Core/ApplicationPool/Process.h +6 -1
- data/src/agent/Core/ApplicationPool/Socket.h +9 -12
- data/src/agent/Core/Controller.h +422 -0
- data/src/agent/Core/{RequestHandler → Controller}/AppResponse.h +2 -0
- data/src/agent/Core/{RequestHandler → Controller}/BufferBody.cpp +27 -5
- data/src/agent/Core/{RequestHandler → Controller}/CheckoutSession.cpp +61 -31
- data/src/agent/Core/{RequestHandler → Controller}/Client.h +5 -2
- data/src/agent/Core/{RequestHandler → Controller}/ForwardResponse.cpp +93 -42
- data/src/agent/Core/{RequestHandler → Controller}/Hooks.cpp +107 -60
- data/src/agent/Core/Controller/Implementation.cpp +38 -0
- data/src/agent/Core/{RequestHandler → Controller}/InitRequest.cpp +134 -80
- data/src/agent/Core/Controller/InitializationAndShutdown.cpp +165 -0
- data/src/agent/Core/{RequestHandler/Utils.cpp → Controller/InternalUtils.cpp} +49 -32
- data/src/agent/Core/Controller/Miscellaneous.cpp +116 -0
- data/src/agent/Core/{RequestHandler → Controller}/Request.h +6 -4
- data/src/agent/Core/{RequestHandler → Controller}/SendRequest.cpp +205 -130
- data/src/agent/Core/Controller/StateInspectionAndConfiguration.cpp +161 -0
- data/src/agent/Core/{RequestHandler → Controller}/TurboCaching.h +3 -0
- data/src/agent/Core/CoreMain.cpp +62 -51
- data/src/agent/Core/OptionParser.h +24 -0
- data/src/agent/Core/ResponseCache.h +5 -5
- data/src/agent/Core/SpawningKit/Config.h +2 -2
- data/src/agent/Core/SpawningKit/SmartSpawner.h +1 -1
- data/src/agent/Core/UnionStation/{Core.h → Context.h} +14 -18
- data/src/agent/Core/UnionStation/StopwatchLog.h +3 -2
- data/src/agent/Core/UnionStation/Transaction.h +7 -7
- data/src/agent/Shared/ApiServerUtils.h +9 -1
- data/src/agent/UstRouter/ApiServer.h +5 -2
- data/src/agent/UstRouter/Controller.h +27 -9
- data/src/agent/UstRouter/UstRouterMain.cpp +1 -0
- data/src/agent/Watchdog/ApiServer.h +5 -2
- data/src/apache2_module/ConfigurationCommands.cpp +7 -0
- data/src/apache2_module/ConfigurationFields.hpp +2 -0
- data/src/apache2_module/ConfigurationSetters.cpp +24 -0
- data/src/apache2_module/CreateDirConfig.cpp +1 -0
- data/src/apache2_module/Hooks.cpp +6 -5
- data/src/apache2_module/MergeDirConfig.cpp +7 -0
- data/src/apache2_module/SetHeaders.cpp +5 -0
- data/src/cxx_supportlib/Constants.h +5 -3
- data/src/cxx_supportlib/SafeLibev.h +2 -1
- data/src/cxx_supportlib/UnionStationFilterSupport.h +2 -1
- data/src/cxx_supportlib/Utils/ReleaseableScopedPointer.h +70 -0
- data/src/cxx_supportlib/vendor-modified/boost/libs/regex/src/regex_raw_buffer.cpp +6 -6
- data/src/helper-scripts/node-loader.js +59 -0
- data/src/nginx_module/CacheLocationConfig.c +48 -0
- data/src/nginx_module/ConfigurationCommands.c +20 -0
- data/src/nginx_module/ConfigurationFields.h +4 -0
- data/src/nginx_module/CreateLocationConfig.c +8 -0
- data/src/nginx_module/MergeLocationConfig.c +12 -0
- data/src/nodejs_supportlib/phusion_passenger/log_express.js +106 -0
- data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +203 -0
- data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +227 -0
- data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +446 -0
- data/src/nodejs_supportlib/vendor-copy/codify/codify.js +44 -0
- data/src/nodejs_supportlib/vendor-copy/codify/package.json +29 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/context.js +200 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/glue.js +488 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/index.js +407 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/index.js +90 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/package.json +40 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/package.json +54 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/listener.js +160 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/index.js +90 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/package.json +40 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/package.json +46 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/package.json +56 -0
- data/src/nodejs_supportlib/vendor-copy/network-byte-order/lib/index.js +102 -0
- data/src/nodejs_supportlib/vendor-copy/network-byte-order/package.json +51 -0
- data/src/nodejs_supportlib/vendor-copy/winston/LICENSE +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston.js +165 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/common.js +483 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config.js +62 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/cli-config.js +35 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/npm-config.js +27 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/syslog-config.js +31 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/container.js +127 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/exception.js +56 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/logger.js +701 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports.js +34 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/console.js +128 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/daily-rotate-file.js +601 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/file.js +675 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/http.js +232 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/memory.js +89 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/transport.js +135 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/webhook.js +146 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/LICENSE +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/lib/async.js +1283 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/package.json +66 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/support/sync-package-managers.js +53 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/MIT-LICENSE.txt +23 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/colors.js +176 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/trap.js +45 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/zalgo.js +104 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/extendStringPrototype.js +118 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/index.js +12 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/america.js +12 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/rainbow.js +13 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/random.js +8 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/zebra.js +5 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/styles.js +77 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/system/supports-colors.js +61 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/package.json +35 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/safe.js +9 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/themes/generic-logging.js +12 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/cycle.js +170 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/package.json +30 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/LICENSE +20 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/lib/eyes.js +236 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/package.json +42 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/LICENSE.md +11 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/isstream.js +27 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/package.json +42 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/LICENSE +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/lib/pkginfo.js +136 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/package.json +56 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/License +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/lib/stack-trace.js +111 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/package.json +33 -0
- data/src/nodejs_supportlib/vendor-copy/winston/package.json +87 -0
- data/src/ruby_supportlib/phusion_passenger.rb +3 -4
- data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +19 -2
- data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
- data/src/ruby_supportlib/phusion_passenger/config/list_instances_command.rb +2 -6
- data/src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb +13 -0
- data/src/ruby_supportlib/phusion_passenger/config/restart_app_command.rb +3 -0
- data/src/ruby_supportlib/phusion_passenger/config/utils.rb +9 -7
- data/src/ruby_supportlib/phusion_passenger/config/validate_install_command.rb +8 -1
- data/src/ruby_supportlib/phusion_passenger/constants.rb +3 -1
- data/src/ruby_supportlib/phusion_passenger/native_support.rb +20 -4
- data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +8 -0
- data/src/ruby_supportlib/phusion_passenger/packaging.rb +1 -0
- data/src/ruby_supportlib/phusion_passenger/platform_info/apache_detector.rb +1 -1
- data/src/ruby_supportlib/phusion_passenger/platform_info/operating_system.rb +11 -4
- data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +1 -1
- data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +647 -0
- data/src/ruby_supportlib/phusion_passenger/standalone/config_utils.rb +229 -15
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +35 -323
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +36 -12
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +123 -14
- data/src/ruby_supportlib/phusion_passenger/standalone/status_command.rb +32 -17
- data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +32 -21
- data/src/ruby_supportlib/phusion_passenger/standalone/version_command.rb +5 -5
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +5 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +68 -24
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +9 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +9 -7
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +3 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +8 -5
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +395 -0
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +10 -7
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +14 -0
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml +4 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +16 -0
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +1 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +1 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +44 -17
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +16 -7
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +1 -1
- metadata +99 -16
- metadata.gz.asc +7 -7
- data/resources/oss-binaries.phusionpassenger.com.crt +0 -248
- data/src/agent/Core/RequestHandler.h +0 -471
@@ -0,0 +1,146 @@
|
|
1
|
+
/*
|
2
|
+
* webhook.js: Transport for logging to remote http endpoints ( POST / RECEIVE webhooks )
|
3
|
+
*
|
4
|
+
* (C) 2011 Marak Squires
|
5
|
+
* MIT LICENCE
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
|
9
|
+
var events = require('events'),
|
10
|
+
http = require('http'),
|
11
|
+
https = require('https'),
|
12
|
+
util = require('util'),
|
13
|
+
cycle = require('cycle'),
|
14
|
+
common = require('../common'),
|
15
|
+
Transport = require('./transport').Transport;
|
16
|
+
|
17
|
+
//
|
18
|
+
// ### function WebHook (options)
|
19
|
+
// #### @options {Object} Options for this instance.
|
20
|
+
// Constructor function for the Console transport object responsible
|
21
|
+
// for making arbitrary HTTP requests whenever log messages and metadata
|
22
|
+
// are received.
|
23
|
+
//
|
24
|
+
var Webhook = exports.Webhook = function (options) {
|
25
|
+
Transport.call(this, options);
|
26
|
+
|
27
|
+
this.name = 'webhook';
|
28
|
+
this.host = options.host || 'localhost';
|
29
|
+
this.port = options.port || 8080;
|
30
|
+
this.method = options.method || 'POST';
|
31
|
+
this.path = options.path || '/winston-log';
|
32
|
+
|
33
|
+
if (options.auth) {
|
34
|
+
this.auth = {};
|
35
|
+
this.auth.username = options.auth.username || '';
|
36
|
+
this.auth.password = options.auth.password || '';
|
37
|
+
}
|
38
|
+
|
39
|
+
if (options.ssl) {
|
40
|
+
this.port = options.port || 443;
|
41
|
+
this.ssl = {
|
42
|
+
key: options.ssl.key || null,
|
43
|
+
cert: options.ssl.cert || null,
|
44
|
+
ca: options.ssl.ca
|
45
|
+
};
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
49
|
+
//
|
50
|
+
// Inherit from `winston.Transport`.
|
51
|
+
//
|
52
|
+
util.inherits(Webhook, Transport);
|
53
|
+
|
54
|
+
//
|
55
|
+
// Expose the name of this Transport on the prototype
|
56
|
+
//
|
57
|
+
Webhook.prototype.name = 'webhook';
|
58
|
+
|
59
|
+
//
|
60
|
+
// ### function log (level, msg, [meta], callback)
|
61
|
+
// #### @level {string} Level at which to log the message.
|
62
|
+
// #### @msg {string} Message to log
|
63
|
+
// #### @meta {Object} **Optional** Additional metadata to attach
|
64
|
+
// #### @callback {function} Continuation to respond to when complete.
|
65
|
+
// Core logging method exposed to Winston. Metadata is optional.
|
66
|
+
//
|
67
|
+
Webhook.prototype.log = function (level, msg, meta, callback) {
|
68
|
+
if (this.silent) {
|
69
|
+
return callback(null, true);
|
70
|
+
}
|
71
|
+
|
72
|
+
var self = this,
|
73
|
+
meta = cycle.decycle(meta),
|
74
|
+
message = common.clone(meta),
|
75
|
+
options,
|
76
|
+
req;
|
77
|
+
|
78
|
+
// Prepare options for outgoing HTTP request
|
79
|
+
options = {
|
80
|
+
host: this.host,
|
81
|
+
port: this.port,
|
82
|
+
path: this.path,
|
83
|
+
method: this.method,
|
84
|
+
headers: { 'Content-Type': 'application/json' }
|
85
|
+
};
|
86
|
+
|
87
|
+
if (this.ssl) {
|
88
|
+
options.ca = this.ssl.ca;
|
89
|
+
options.key = this.ssl.key;
|
90
|
+
options.cert = this.ssl.cert;
|
91
|
+
|
92
|
+
// Required for the test fixture SSL certificate to be considered valid.
|
93
|
+
options.rejectUnauthorized = false;
|
94
|
+
}
|
95
|
+
|
96
|
+
if (this.auth) {
|
97
|
+
// Encode `Authorization` header used by Basic Auth
|
98
|
+
options.headers['Authorization'] = 'Basic ' + new Buffer(
|
99
|
+
this.auth.username + ':' + this.auth.password, 'utf8'
|
100
|
+
).toString('base64');
|
101
|
+
}
|
102
|
+
|
103
|
+
// Perform HTTP logging request
|
104
|
+
req = (self.ssl ? https : http).request(options, function (res) {
|
105
|
+
// TODO: emit 'logged' correctly,
|
106
|
+
// keep track of pending logs.
|
107
|
+
res.on('data', function(data) {
|
108
|
+
// Do nothing. We need to read the response, or we run into maxSockets
|
109
|
+
// after 5 requests.
|
110
|
+
});
|
111
|
+
|
112
|
+
self.emit('logged');
|
113
|
+
if (callback) callback(null, true);
|
114
|
+
callback = null;
|
115
|
+
});
|
116
|
+
|
117
|
+
req.on('error', function (err) {
|
118
|
+
//
|
119
|
+
// Propagate the `error` back up to the `Logger` that this
|
120
|
+
// instance belongs to.
|
121
|
+
//
|
122
|
+
self.emit('error', err);
|
123
|
+
if (callback) callback(err, false);
|
124
|
+
callback = null;
|
125
|
+
});
|
126
|
+
|
127
|
+
//
|
128
|
+
// Write logging event to the outgoing request body
|
129
|
+
//
|
130
|
+
// jsonMessage is currently conforming to JSON-RPC v1.0,
|
131
|
+
// but without the unique id since there is no anticipated response
|
132
|
+
// see: http://en.wikipedia.org/wiki/JSON-RPC
|
133
|
+
//
|
134
|
+
|
135
|
+
var params = common.clone(meta) || {};
|
136
|
+
params.timestamp = new Date();
|
137
|
+
params.message = msg;
|
138
|
+
params.level = level;
|
139
|
+
|
140
|
+
req.write(JSON.stringify({
|
141
|
+
method: 'log',
|
142
|
+
params: params
|
143
|
+
}));
|
144
|
+
|
145
|
+
req.end();
|
146
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010-2014 Caolan McMahon
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
@@ -0,0 +1,1283 @@
|
|
1
|
+
/*!
|
2
|
+
* async
|
3
|
+
* https://github.com/caolan/async
|
4
|
+
*
|
5
|
+
* Copyright 2010-2014 Caolan McMahon
|
6
|
+
* Released under the MIT license
|
7
|
+
*/
|
8
|
+
(function () {
|
9
|
+
|
10
|
+
var async = {};
|
11
|
+
var noop = function () {};
|
12
|
+
|
13
|
+
// global on the server, window in the browser
|
14
|
+
var root, previous_async;
|
15
|
+
|
16
|
+
if (typeof window == 'object' && this === window) {
|
17
|
+
root = window;
|
18
|
+
}
|
19
|
+
else if (typeof global == 'object' && this === global) {
|
20
|
+
root = global;
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
root = this;
|
24
|
+
}
|
25
|
+
|
26
|
+
if (root != null) {
|
27
|
+
previous_async = root.async;
|
28
|
+
}
|
29
|
+
|
30
|
+
async.noConflict = function () {
|
31
|
+
root.async = previous_async;
|
32
|
+
return async;
|
33
|
+
};
|
34
|
+
|
35
|
+
function only_once(fn) {
|
36
|
+
var called = false;
|
37
|
+
return function() {
|
38
|
+
if (called) throw new Error("Callback was already called.");
|
39
|
+
called = true;
|
40
|
+
fn.apply(root, arguments);
|
41
|
+
};
|
42
|
+
}
|
43
|
+
|
44
|
+
//// cross-browser compatiblity functions ////
|
45
|
+
|
46
|
+
var _toString = Object.prototype.toString;
|
47
|
+
|
48
|
+
var _isArray = Array.isArray || function (obj) {
|
49
|
+
return _toString.call(obj) === '[object Array]';
|
50
|
+
};
|
51
|
+
|
52
|
+
var _each = function (arr, iterator) {
|
53
|
+
var index = -1,
|
54
|
+
length = arr.length;
|
55
|
+
|
56
|
+
while (++index < length) {
|
57
|
+
iterator(arr[index], index, arr);
|
58
|
+
}
|
59
|
+
};
|
60
|
+
|
61
|
+
var _map = function (arr, iterator) {
|
62
|
+
var index = -1,
|
63
|
+
length = arr.length,
|
64
|
+
result = Array(length);
|
65
|
+
|
66
|
+
while (++index < length) {
|
67
|
+
result[index] = iterator(arr[index], index, arr);
|
68
|
+
}
|
69
|
+
return result;
|
70
|
+
};
|
71
|
+
|
72
|
+
var _reduce = function (arr, iterator, memo) {
|
73
|
+
_each(arr, function (x, i, a) {
|
74
|
+
memo = iterator(memo, x, i, a);
|
75
|
+
});
|
76
|
+
return memo;
|
77
|
+
};
|
78
|
+
|
79
|
+
var _forEachOf = function (object, iterator) {
|
80
|
+
_each(_keys(object), function (key) {
|
81
|
+
iterator(object[key], key);
|
82
|
+
});
|
83
|
+
};
|
84
|
+
|
85
|
+
var _keys = Object.keys || function (obj) {
|
86
|
+
var keys = [];
|
87
|
+
for (var k in obj) {
|
88
|
+
if (obj.hasOwnProperty(k)) {
|
89
|
+
keys.push(k);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
return keys;
|
93
|
+
};
|
94
|
+
|
95
|
+
var _baseSlice = function (arr, start) {
|
96
|
+
start = start || 0;
|
97
|
+
var index = -1;
|
98
|
+
var length = arr.length;
|
99
|
+
|
100
|
+
if (start) {
|
101
|
+
length -= start;
|
102
|
+
length = length < 0 ? 0 : length;
|
103
|
+
}
|
104
|
+
var result = Array(length);
|
105
|
+
|
106
|
+
while (++index < length) {
|
107
|
+
result[index] = arr[index + start];
|
108
|
+
}
|
109
|
+
return result;
|
110
|
+
};
|
111
|
+
|
112
|
+
//// exported async module functions ////
|
113
|
+
|
114
|
+
//// nextTick implementation with browser-compatible fallback ////
|
115
|
+
|
116
|
+
// capture the global reference to guard against fakeTimer mocks
|
117
|
+
var _setImmediate;
|
118
|
+
if (typeof setImmediate === 'function') {
|
119
|
+
_setImmediate = setImmediate;
|
120
|
+
}
|
121
|
+
|
122
|
+
if (typeof process === 'undefined' || !(process.nextTick)) {
|
123
|
+
if (_setImmediate) {
|
124
|
+
async.nextTick = function (fn) {
|
125
|
+
// not a direct alias for IE10 compatibility
|
126
|
+
_setImmediate(fn);
|
127
|
+
};
|
128
|
+
async.setImmediate = async.nextTick;
|
129
|
+
}
|
130
|
+
else {
|
131
|
+
async.nextTick = function (fn) {
|
132
|
+
setTimeout(fn, 0);
|
133
|
+
};
|
134
|
+
async.setImmediate = async.nextTick;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
else {
|
138
|
+
async.nextTick = process.nextTick;
|
139
|
+
if (_setImmediate) {
|
140
|
+
async.setImmediate = function (fn) {
|
141
|
+
// not a direct alias for IE10 compatibility
|
142
|
+
_setImmediate(fn);
|
143
|
+
};
|
144
|
+
}
|
145
|
+
else {
|
146
|
+
async.setImmediate = async.nextTick;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
async.each = function (arr, iterator, callback) {
|
151
|
+
callback = callback || noop;
|
152
|
+
if (!arr.length) {
|
153
|
+
return callback();
|
154
|
+
}
|
155
|
+
var completed = 0;
|
156
|
+
_each(arr, function (x) {
|
157
|
+
iterator(x, only_once(done) );
|
158
|
+
});
|
159
|
+
function done(err) {
|
160
|
+
if (err) {
|
161
|
+
callback(err);
|
162
|
+
callback = noop;
|
163
|
+
}
|
164
|
+
else {
|
165
|
+
completed += 1;
|
166
|
+
if (completed >= arr.length) {
|
167
|
+
callback();
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
};
|
172
|
+
async.forEach = async.each;
|
173
|
+
|
174
|
+
async.eachSeries = function (arr, iterator, callback) {
|
175
|
+
callback = callback || noop;
|
176
|
+
if (!arr.length) {
|
177
|
+
return callback();
|
178
|
+
}
|
179
|
+
var completed = 0;
|
180
|
+
var iterate = function () {
|
181
|
+
iterator(arr[completed], function (err) {
|
182
|
+
if (err) {
|
183
|
+
callback(err);
|
184
|
+
callback = noop;
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
completed += 1;
|
188
|
+
if (completed >= arr.length) {
|
189
|
+
callback();
|
190
|
+
}
|
191
|
+
else {
|
192
|
+
iterate();
|
193
|
+
}
|
194
|
+
}
|
195
|
+
});
|
196
|
+
};
|
197
|
+
iterate();
|
198
|
+
};
|
199
|
+
async.forEachSeries = async.eachSeries;
|
200
|
+
|
201
|
+
|
202
|
+
async.eachLimit = function (arr, limit, iterator, callback) {
|
203
|
+
var fn = _eachLimit(limit);
|
204
|
+
fn.apply(null, [arr, iterator, callback]);
|
205
|
+
};
|
206
|
+
async.forEachLimit = async.eachLimit;
|
207
|
+
|
208
|
+
var _eachLimit = function (limit) {
|
209
|
+
|
210
|
+
return function (arr, iterator, callback) {
|
211
|
+
callback = callback || noop;
|
212
|
+
if (!arr.length || limit <= 0) {
|
213
|
+
return callback();
|
214
|
+
}
|
215
|
+
var completed = 0;
|
216
|
+
var started = 0;
|
217
|
+
var running = 0;
|
218
|
+
|
219
|
+
(function replenish () {
|
220
|
+
if (completed >= arr.length) {
|
221
|
+
return callback();
|
222
|
+
}
|
223
|
+
|
224
|
+
while (running < limit && started < arr.length) {
|
225
|
+
started += 1;
|
226
|
+
running += 1;
|
227
|
+
iterator(arr[started - 1], function (err) {
|
228
|
+
if (err) {
|
229
|
+
callback(err);
|
230
|
+
callback = noop;
|
231
|
+
}
|
232
|
+
else {
|
233
|
+
completed += 1;
|
234
|
+
running -= 1;
|
235
|
+
if (completed >= arr.length) {
|
236
|
+
callback();
|
237
|
+
}
|
238
|
+
else {
|
239
|
+
replenish();
|
240
|
+
}
|
241
|
+
}
|
242
|
+
});
|
243
|
+
}
|
244
|
+
})();
|
245
|
+
};
|
246
|
+
};
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
async.forEachOf = async.eachOf = function (object, iterator, callback) {
|
251
|
+
callback = callback || function () {};
|
252
|
+
var size = object.length || _keys(object).length;
|
253
|
+
var completed = 0;
|
254
|
+
if (!size) {
|
255
|
+
return callback();
|
256
|
+
}
|
257
|
+
_forEachOf(object, function (value, key) {
|
258
|
+
iterator(object[key], key, function (err) {
|
259
|
+
if (err) {
|
260
|
+
callback(err);
|
261
|
+
callback = function () {};
|
262
|
+
} else {
|
263
|
+
completed += 1;
|
264
|
+
if (completed === size) {
|
265
|
+
callback(null);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
});
|
269
|
+
});
|
270
|
+
};
|
271
|
+
|
272
|
+
async.forEachOfSeries = async.eachOfSeries = function (obj, iterator, callback) {
|
273
|
+
callback = callback || function () {};
|
274
|
+
var keys = _keys(obj);
|
275
|
+
var size = keys.length;
|
276
|
+
if (!size) {
|
277
|
+
return callback();
|
278
|
+
}
|
279
|
+
var completed = 0;
|
280
|
+
var iterate = function () {
|
281
|
+
var sync = true;
|
282
|
+
var key = keys[completed];
|
283
|
+
iterator(obj[key], key, function (err) {
|
284
|
+
if (err) {
|
285
|
+
callback(err);
|
286
|
+
callback = function () {};
|
287
|
+
}
|
288
|
+
else {
|
289
|
+
completed += 1;
|
290
|
+
if (completed >= size) {
|
291
|
+
callback(null);
|
292
|
+
}
|
293
|
+
else {
|
294
|
+
if (sync) {
|
295
|
+
async.nextTick(iterate);
|
296
|
+
}
|
297
|
+
else {
|
298
|
+
iterate();
|
299
|
+
}
|
300
|
+
}
|
301
|
+
}
|
302
|
+
});
|
303
|
+
sync = false;
|
304
|
+
};
|
305
|
+
iterate();
|
306
|
+
};
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
async.forEachOfLimit = async.eachOfLimit = function (obj, limit, iterator, callback) {
|
311
|
+
_forEachOfLimit(limit)(obj, iterator, callback);
|
312
|
+
};
|
313
|
+
|
314
|
+
var _forEachOfLimit = function (limit) {
|
315
|
+
|
316
|
+
return function (obj, iterator, callback) {
|
317
|
+
callback = callback || function () {};
|
318
|
+
var keys = _keys(obj);
|
319
|
+
var size = keys.length;
|
320
|
+
if (!size || limit <= 0) {
|
321
|
+
return callback();
|
322
|
+
}
|
323
|
+
var completed = 0;
|
324
|
+
var started = 0;
|
325
|
+
var running = 0;
|
326
|
+
|
327
|
+
(function replenish () {
|
328
|
+
if (completed >= size) {
|
329
|
+
return callback();
|
330
|
+
}
|
331
|
+
|
332
|
+
while (running < limit && started < size) {
|
333
|
+
started += 1;
|
334
|
+
running += 1;
|
335
|
+
var key = keys[started - 1];
|
336
|
+
iterator(obj[key], key, function (err) {
|
337
|
+
if (err) {
|
338
|
+
callback(err);
|
339
|
+
callback = function () {};
|
340
|
+
}
|
341
|
+
else {
|
342
|
+
completed += 1;
|
343
|
+
running -= 1;
|
344
|
+
if (completed >= size) {
|
345
|
+
callback();
|
346
|
+
}
|
347
|
+
else {
|
348
|
+
replenish();
|
349
|
+
}
|
350
|
+
}
|
351
|
+
});
|
352
|
+
}
|
353
|
+
})();
|
354
|
+
};
|
355
|
+
};
|
356
|
+
|
357
|
+
|
358
|
+
var doParallel = function (fn) {
|
359
|
+
return function () {
|
360
|
+
var args = _baseSlice(arguments);
|
361
|
+
return fn.apply(null, [async.each].concat(args));
|
362
|
+
};
|
363
|
+
};
|
364
|
+
var doParallelLimit = function(limit, fn) {
|
365
|
+
return function () {
|
366
|
+
var args = _baseSlice(arguments);
|
367
|
+
return fn.apply(null, [_eachLimit(limit)].concat(args));
|
368
|
+
};
|
369
|
+
};
|
370
|
+
var doSeries = function (fn) {
|
371
|
+
return function () {
|
372
|
+
var args = _baseSlice(arguments);
|
373
|
+
return fn.apply(null, [async.eachSeries].concat(args));
|
374
|
+
};
|
375
|
+
};
|
376
|
+
|
377
|
+
|
378
|
+
var _asyncMap = function (eachfn, arr, iterator, callback) {
|
379
|
+
arr = _map(arr, function (x, i) {
|
380
|
+
return {index: i, value: x};
|
381
|
+
});
|
382
|
+
if (!callback) {
|
383
|
+
eachfn(arr, function (x, callback) {
|
384
|
+
iterator(x.value, function (err) {
|
385
|
+
callback(err);
|
386
|
+
});
|
387
|
+
});
|
388
|
+
} else {
|
389
|
+
var results = [];
|
390
|
+
eachfn(arr, function (x, callback) {
|
391
|
+
iterator(x.value, function (err, v) {
|
392
|
+
results[x.index] = v;
|
393
|
+
callback(err);
|
394
|
+
});
|
395
|
+
}, function (err) {
|
396
|
+
callback(err, results);
|
397
|
+
});
|
398
|
+
}
|
399
|
+
};
|
400
|
+
async.map = doParallel(_asyncMap);
|
401
|
+
async.mapSeries = doSeries(_asyncMap);
|
402
|
+
async.mapLimit = function (arr, limit, iterator, callback) {
|
403
|
+
return _mapLimit(limit)(arr, iterator, callback);
|
404
|
+
};
|
405
|
+
|
406
|
+
var _mapLimit = function(limit) {
|
407
|
+
return doParallelLimit(limit, _asyncMap);
|
408
|
+
};
|
409
|
+
|
410
|
+
// reduce only has a series version, as doing reduce in parallel won't
|
411
|
+
// work in many situations.
|
412
|
+
async.reduce = function (arr, memo, iterator, callback) {
|
413
|
+
async.eachSeries(arr, function (x, callback) {
|
414
|
+
iterator(memo, x, function (err, v) {
|
415
|
+
memo = v;
|
416
|
+
callback(err);
|
417
|
+
});
|
418
|
+
}, function (err) {
|
419
|
+
callback(err, memo);
|
420
|
+
});
|
421
|
+
};
|
422
|
+
// inject alias
|
423
|
+
async.inject = async.reduce;
|
424
|
+
// foldl alias
|
425
|
+
async.foldl = async.reduce;
|
426
|
+
|
427
|
+
async.reduceRight = function (arr, memo, iterator, callback) {
|
428
|
+
var reversed = _map(arr, function (x) {
|
429
|
+
return x;
|
430
|
+
}).reverse();
|
431
|
+
async.reduce(reversed, memo, iterator, callback);
|
432
|
+
};
|
433
|
+
// foldr alias
|
434
|
+
async.foldr = async.reduceRight;
|
435
|
+
|
436
|
+
var _filter = function (eachfn, arr, iterator, callback) {
|
437
|
+
var results = [];
|
438
|
+
arr = _map(arr, function (x, i) {
|
439
|
+
return {index: i, value: x};
|
440
|
+
});
|
441
|
+
eachfn(arr, function (x, callback) {
|
442
|
+
iterator(x.value, function (v) {
|
443
|
+
if (v) {
|
444
|
+
results.push(x);
|
445
|
+
}
|
446
|
+
callback();
|
447
|
+
});
|
448
|
+
}, function (err) {
|
449
|
+
callback(_map(results.sort(function (a, b) {
|
450
|
+
return a.index - b.index;
|
451
|
+
}), function (x) {
|
452
|
+
return x.value;
|
453
|
+
}));
|
454
|
+
});
|
455
|
+
};
|
456
|
+
async.filter = doParallel(_filter);
|
457
|
+
async.filterSeries = doSeries(_filter);
|
458
|
+
// select alias
|
459
|
+
async.select = async.filter;
|
460
|
+
async.selectSeries = async.filterSeries;
|
461
|
+
|
462
|
+
var _reject = function (eachfn, arr, iterator, callback) {
|
463
|
+
var results = [];
|
464
|
+
arr = _map(arr, function (x, i) {
|
465
|
+
return {index: i, value: x};
|
466
|
+
});
|
467
|
+
eachfn(arr, function (x, callback) {
|
468
|
+
iterator(x.value, function (v) {
|
469
|
+
if (!v) {
|
470
|
+
results.push(x);
|
471
|
+
}
|
472
|
+
callback();
|
473
|
+
});
|
474
|
+
}, function (err) {
|
475
|
+
callback(_map(results.sort(function (a, b) {
|
476
|
+
return a.index - b.index;
|
477
|
+
}), function (x) {
|
478
|
+
return x.value;
|
479
|
+
}));
|
480
|
+
});
|
481
|
+
};
|
482
|
+
async.reject = doParallel(_reject);
|
483
|
+
async.rejectSeries = doSeries(_reject);
|
484
|
+
|
485
|
+
var _detect = function (eachfn, arr, iterator, main_callback) {
|
486
|
+
eachfn(arr, function (x, callback) {
|
487
|
+
iterator(x, function (result) {
|
488
|
+
if (result) {
|
489
|
+
main_callback(x);
|
490
|
+
main_callback = noop;
|
491
|
+
}
|
492
|
+
else {
|
493
|
+
callback();
|
494
|
+
}
|
495
|
+
});
|
496
|
+
}, function (err) {
|
497
|
+
main_callback();
|
498
|
+
});
|
499
|
+
};
|
500
|
+
async.detect = doParallel(_detect);
|
501
|
+
async.detectSeries = doSeries(_detect);
|
502
|
+
|
503
|
+
async.some = function (arr, iterator, main_callback) {
|
504
|
+
async.each(arr, function (x, callback) {
|
505
|
+
iterator(x, function (v) {
|
506
|
+
if (v) {
|
507
|
+
main_callback(true);
|
508
|
+
main_callback = noop;
|
509
|
+
}
|
510
|
+
callback();
|
511
|
+
});
|
512
|
+
}, function (err) {
|
513
|
+
main_callback(false);
|
514
|
+
});
|
515
|
+
};
|
516
|
+
// any alias
|
517
|
+
async.any = async.some;
|
518
|
+
|
519
|
+
async.every = function (arr, iterator, main_callback) {
|
520
|
+
async.each(arr, function (x, callback) {
|
521
|
+
iterator(x, function (v) {
|
522
|
+
if (!v) {
|
523
|
+
main_callback(false);
|
524
|
+
main_callback = noop;
|
525
|
+
}
|
526
|
+
callback();
|
527
|
+
});
|
528
|
+
}, function (err) {
|
529
|
+
main_callback(true);
|
530
|
+
});
|
531
|
+
};
|
532
|
+
// all alias
|
533
|
+
async.all = async.every;
|
534
|
+
|
535
|
+
async.sortBy = function (arr, iterator, callback) {
|
536
|
+
async.map(arr, function (x, callback) {
|
537
|
+
iterator(x, function (err, criteria) {
|
538
|
+
if (err) {
|
539
|
+
callback(err);
|
540
|
+
}
|
541
|
+
else {
|
542
|
+
callback(null, {value: x, criteria: criteria});
|
543
|
+
}
|
544
|
+
});
|
545
|
+
}, function (err, results) {
|
546
|
+
if (err) {
|
547
|
+
return callback(err);
|
548
|
+
}
|
549
|
+
else {
|
550
|
+
var fn = function (left, right) {
|
551
|
+
var a = left.criteria, b = right.criteria;
|
552
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
553
|
+
};
|
554
|
+
callback(null, _map(results.sort(fn), function (x) {
|
555
|
+
return x.value;
|
556
|
+
}));
|
557
|
+
}
|
558
|
+
});
|
559
|
+
};
|
560
|
+
|
561
|
+
async.auto = function (tasks, callback) {
|
562
|
+
callback = callback || noop;
|
563
|
+
var keys = _keys(tasks);
|
564
|
+
var remainingTasks = keys.length;
|
565
|
+
if (!remainingTasks) {
|
566
|
+
return callback();
|
567
|
+
}
|
568
|
+
|
569
|
+
var results = {};
|
570
|
+
|
571
|
+
var listeners = [];
|
572
|
+
var addListener = function (fn) {
|
573
|
+
listeners.unshift(fn);
|
574
|
+
};
|
575
|
+
var removeListener = function (fn) {
|
576
|
+
for (var i = 0; i < listeners.length; i += 1) {
|
577
|
+
if (listeners[i] === fn) {
|
578
|
+
listeners.splice(i, 1);
|
579
|
+
return;
|
580
|
+
}
|
581
|
+
}
|
582
|
+
};
|
583
|
+
var taskComplete = function () {
|
584
|
+
remainingTasks--;
|
585
|
+
_each(listeners.slice(0), function (fn) {
|
586
|
+
fn();
|
587
|
+
});
|
588
|
+
};
|
589
|
+
|
590
|
+
addListener(function () {
|
591
|
+
if (!remainingTasks) {
|
592
|
+
var theCallback = callback;
|
593
|
+
// prevent final callback from calling itself if it errors
|
594
|
+
callback = noop;
|
595
|
+
|
596
|
+
theCallback(null, results);
|
597
|
+
}
|
598
|
+
});
|
599
|
+
|
600
|
+
_each(keys, function (k) {
|
601
|
+
var task = _isArray(tasks[k]) ? tasks[k]: [tasks[k]];
|
602
|
+
var taskCallback = function (err) {
|
603
|
+
var args = _baseSlice(arguments, 1);
|
604
|
+
if (args.length <= 1) {
|
605
|
+
args = args[0];
|
606
|
+
}
|
607
|
+
if (err) {
|
608
|
+
var safeResults = {};
|
609
|
+
_each(_keys(results), function(rkey) {
|
610
|
+
safeResults[rkey] = results[rkey];
|
611
|
+
});
|
612
|
+
safeResults[k] = args;
|
613
|
+
callback(err, safeResults);
|
614
|
+
// stop subsequent errors hitting callback multiple times
|
615
|
+
callback = noop;
|
616
|
+
}
|
617
|
+
else {
|
618
|
+
results[k] = args;
|
619
|
+
async.setImmediate(taskComplete);
|
620
|
+
}
|
621
|
+
};
|
622
|
+
var requires = task.slice(0, Math.abs(task.length - 1)) || [];
|
623
|
+
// prevent dead-locks
|
624
|
+
var len = requires.length;
|
625
|
+
var dep;
|
626
|
+
while (len--) {
|
627
|
+
if (!(dep = tasks[requires[len]])) {
|
628
|
+
throw new Error('Has inexistant dependency');
|
629
|
+
}
|
630
|
+
if (_isArray(dep) && !!~dep.indexOf(k)) {
|
631
|
+
throw new Error('Has cyclic dependencies');
|
632
|
+
}
|
633
|
+
}
|
634
|
+
var ready = function () {
|
635
|
+
return _reduce(requires, function (a, x) {
|
636
|
+
return (a && results.hasOwnProperty(x));
|
637
|
+
}, true) && !results.hasOwnProperty(k);
|
638
|
+
};
|
639
|
+
if (ready()) {
|
640
|
+
task[task.length - 1](taskCallback, results);
|
641
|
+
}
|
642
|
+
else {
|
643
|
+
var listener = function () {
|
644
|
+
if (ready()) {
|
645
|
+
removeListener(listener);
|
646
|
+
task[task.length - 1](taskCallback, results);
|
647
|
+
}
|
648
|
+
};
|
649
|
+
addListener(listener);
|
650
|
+
}
|
651
|
+
});
|
652
|
+
};
|
653
|
+
|
654
|
+
async.retry = function(times, task, callback) {
|
655
|
+
var DEFAULT_TIMES = 5;
|
656
|
+
var attempts = [];
|
657
|
+
// Use defaults if times not passed
|
658
|
+
if (typeof times === 'function') {
|
659
|
+
callback = task;
|
660
|
+
task = times;
|
661
|
+
times = DEFAULT_TIMES;
|
662
|
+
}
|
663
|
+
// Make sure times is a number
|
664
|
+
times = parseInt(times, 10) || DEFAULT_TIMES;
|
665
|
+
var wrappedTask = function(wrappedCallback, wrappedResults) {
|
666
|
+
var retryAttempt = function(task, finalAttempt) {
|
667
|
+
return function(seriesCallback) {
|
668
|
+
task(function(err, result){
|
669
|
+
seriesCallback(!err || finalAttempt, {err: err, result: result});
|
670
|
+
}, wrappedResults);
|
671
|
+
};
|
672
|
+
};
|
673
|
+
while (times) {
|
674
|
+
attempts.push(retryAttempt(task, !(times-=1)));
|
675
|
+
}
|
676
|
+
async.series(attempts, function(done, data){
|
677
|
+
data = data[data.length - 1];
|
678
|
+
(wrappedCallback || callback)(data.err, data.result);
|
679
|
+
});
|
680
|
+
};
|
681
|
+
// If a callback is passed, run this as a controll flow
|
682
|
+
return callback ? wrappedTask() : wrappedTask;
|
683
|
+
};
|
684
|
+
|
685
|
+
async.waterfall = function (tasks, callback) {
|
686
|
+
callback = callback || noop;
|
687
|
+
if (!_isArray(tasks)) {
|
688
|
+
var err = new Error('First argument to waterfall must be an array of functions');
|
689
|
+
return callback(err);
|
690
|
+
}
|
691
|
+
if (!tasks.length) {
|
692
|
+
return callback();
|
693
|
+
}
|
694
|
+
var wrapIterator = function (iterator) {
|
695
|
+
return function (err) {
|
696
|
+
if (err) {
|
697
|
+
callback.apply(null, arguments);
|
698
|
+
callback = noop;
|
699
|
+
}
|
700
|
+
else {
|
701
|
+
var args = _baseSlice(arguments, 1);
|
702
|
+
var next = iterator.next();
|
703
|
+
if (next) {
|
704
|
+
args.push(wrapIterator(next));
|
705
|
+
}
|
706
|
+
else {
|
707
|
+
args.push(callback);
|
708
|
+
}
|
709
|
+
async.setImmediate(function () {
|
710
|
+
iterator.apply(null, args);
|
711
|
+
});
|
712
|
+
}
|
713
|
+
};
|
714
|
+
};
|
715
|
+
wrapIterator(async.iterator(tasks))();
|
716
|
+
};
|
717
|
+
|
718
|
+
var _parallel = function(eachfn, tasks, callback) {
|
719
|
+
callback = callback || noop;
|
720
|
+
if (_isArray(tasks)) {
|
721
|
+
eachfn.map(tasks, function (fn, callback) {
|
722
|
+
if (fn) {
|
723
|
+
fn(function (err) {
|
724
|
+
var args = _baseSlice(arguments, 1);
|
725
|
+
if (args.length <= 1) {
|
726
|
+
args = args[0];
|
727
|
+
}
|
728
|
+
callback.call(null, err, args);
|
729
|
+
});
|
730
|
+
}
|
731
|
+
}, callback);
|
732
|
+
}
|
733
|
+
else {
|
734
|
+
var results = {};
|
735
|
+
eachfn.each(_keys(tasks), function (k, callback) {
|
736
|
+
tasks[k](function (err) {
|
737
|
+
var args = _baseSlice(arguments, 1);
|
738
|
+
if (args.length <= 1) {
|
739
|
+
args = args[0];
|
740
|
+
}
|
741
|
+
results[k] = args;
|
742
|
+
callback(err);
|
743
|
+
});
|
744
|
+
}, function (err) {
|
745
|
+
callback(err, results);
|
746
|
+
});
|
747
|
+
}
|
748
|
+
};
|
749
|
+
|
750
|
+
async.parallel = function (tasks, callback) {
|
751
|
+
_parallel({ map: async.map, each: async.each }, tasks, callback);
|
752
|
+
};
|
753
|
+
|
754
|
+
async.parallelLimit = function(tasks, limit, callback) {
|
755
|
+
_parallel({ map: _mapLimit(limit), each: _eachLimit(limit) }, tasks, callback);
|
756
|
+
};
|
757
|
+
|
758
|
+
async.series = function (tasks, callback) {
|
759
|
+
callback = callback || noop;
|
760
|
+
if (_isArray(tasks)) {
|
761
|
+
async.mapSeries(tasks, function (fn, callback) {
|
762
|
+
if (fn) {
|
763
|
+
fn(function (err) {
|
764
|
+
var args = _baseSlice(arguments, 1);
|
765
|
+
if (args.length <= 1) {
|
766
|
+
args = args[0];
|
767
|
+
}
|
768
|
+
callback.call(null, err, args);
|
769
|
+
});
|
770
|
+
}
|
771
|
+
}, callback);
|
772
|
+
}
|
773
|
+
else {
|
774
|
+
var results = {};
|
775
|
+
async.eachSeries(_keys(tasks), function (k, callback) {
|
776
|
+
tasks[k](function (err) {
|
777
|
+
var args = _baseSlice(arguments, 1);
|
778
|
+
if (args.length <= 1) {
|
779
|
+
args = args[0];
|
780
|
+
}
|
781
|
+
results[k] = args;
|
782
|
+
callback(err);
|
783
|
+
});
|
784
|
+
}, function (err) {
|
785
|
+
callback(err, results);
|
786
|
+
});
|
787
|
+
}
|
788
|
+
};
|
789
|
+
|
790
|
+
async.iterator = function (tasks) {
|
791
|
+
var makeCallback = function (index) {
|
792
|
+
var fn = function () {
|
793
|
+
if (tasks.length) {
|
794
|
+
tasks[index].apply(null, arguments);
|
795
|
+
}
|
796
|
+
return fn.next();
|
797
|
+
};
|
798
|
+
fn.next = function () {
|
799
|
+
return (index < tasks.length - 1) ? makeCallback(index + 1): null;
|
800
|
+
};
|
801
|
+
return fn;
|
802
|
+
};
|
803
|
+
return makeCallback(0);
|
804
|
+
};
|
805
|
+
|
806
|
+
async.apply = function (fn) {
|
807
|
+
var args = _baseSlice(arguments, 1);
|
808
|
+
return function () {
|
809
|
+
return fn.apply(
|
810
|
+
null, args.concat(_baseSlice(arguments))
|
811
|
+
);
|
812
|
+
};
|
813
|
+
};
|
814
|
+
|
815
|
+
var _concat = function (eachfn, arr, fn, callback) {
|
816
|
+
var r = [];
|
817
|
+
eachfn(arr, function (x, cb) {
|
818
|
+
fn(x, function (err, y) {
|
819
|
+
r = r.concat(y || []);
|
820
|
+
cb(err);
|
821
|
+
});
|
822
|
+
}, function (err) {
|
823
|
+
callback(err, r);
|
824
|
+
});
|
825
|
+
};
|
826
|
+
async.concat = doParallel(_concat);
|
827
|
+
async.concatSeries = doSeries(_concat);
|
828
|
+
|
829
|
+
async.whilst = function (test, iterator, callback) {
|
830
|
+
if (test()) {
|
831
|
+
iterator(function (err) {
|
832
|
+
if (err) {
|
833
|
+
return callback(err);
|
834
|
+
}
|
835
|
+
async.whilst(test, iterator, callback);
|
836
|
+
});
|
837
|
+
}
|
838
|
+
else {
|
839
|
+
callback();
|
840
|
+
}
|
841
|
+
};
|
842
|
+
|
843
|
+
async.doWhilst = function (iterator, test, callback) {
|
844
|
+
iterator(function (err) {
|
845
|
+
if (err) {
|
846
|
+
return callback(err);
|
847
|
+
}
|
848
|
+
var args = _baseSlice(arguments, 1);
|
849
|
+
if (test.apply(null, args)) {
|
850
|
+
async.doWhilst(iterator, test, callback);
|
851
|
+
}
|
852
|
+
else {
|
853
|
+
callback();
|
854
|
+
}
|
855
|
+
});
|
856
|
+
};
|
857
|
+
|
858
|
+
async.until = function (test, iterator, callback) {
|
859
|
+
if (!test()) {
|
860
|
+
iterator(function (err) {
|
861
|
+
if (err) {
|
862
|
+
return callback(err);
|
863
|
+
}
|
864
|
+
async.until(test, iterator, callback);
|
865
|
+
});
|
866
|
+
}
|
867
|
+
else {
|
868
|
+
callback();
|
869
|
+
}
|
870
|
+
};
|
871
|
+
|
872
|
+
async.doUntil = function (iterator, test, callback) {
|
873
|
+
iterator(function (err) {
|
874
|
+
if (err) {
|
875
|
+
return callback(err);
|
876
|
+
}
|
877
|
+
var args = _baseSlice(arguments, 1);
|
878
|
+
if (!test.apply(null, args)) {
|
879
|
+
async.doUntil(iterator, test, callback);
|
880
|
+
}
|
881
|
+
else {
|
882
|
+
callback();
|
883
|
+
}
|
884
|
+
});
|
885
|
+
};
|
886
|
+
|
887
|
+
async.queue = function (worker, concurrency) {
|
888
|
+
if (concurrency === undefined) {
|
889
|
+
concurrency = 1;
|
890
|
+
}
|
891
|
+
else if(concurrency === 0) {
|
892
|
+
throw new Error('Concurrency must not be zero');
|
893
|
+
}
|
894
|
+
function _insert(q, data, pos, callback) {
|
895
|
+
if (!q.started){
|
896
|
+
q.started = true;
|
897
|
+
}
|
898
|
+
if (!_isArray(data)) {
|
899
|
+
data = [data];
|
900
|
+
}
|
901
|
+
if(data.length === 0) {
|
902
|
+
// call drain immediately if there are no tasks
|
903
|
+
return async.setImmediate(function() {
|
904
|
+
if (q.drain) {
|
905
|
+
q.drain();
|
906
|
+
}
|
907
|
+
});
|
908
|
+
}
|
909
|
+
_each(data, function(task) {
|
910
|
+
var item = {
|
911
|
+
data: task,
|
912
|
+
callback: typeof callback === 'function' ? callback : null
|
913
|
+
};
|
914
|
+
|
915
|
+
if (pos) {
|
916
|
+
q.tasks.unshift(item);
|
917
|
+
} else {
|
918
|
+
q.tasks.push(item);
|
919
|
+
}
|
920
|
+
|
921
|
+
if (q.saturated && q.tasks.length === q.concurrency) {
|
922
|
+
q.saturated();
|
923
|
+
}
|
924
|
+
async.setImmediate(q.process);
|
925
|
+
});
|
926
|
+
}
|
927
|
+
|
928
|
+
var workers = 0;
|
929
|
+
var q = {
|
930
|
+
tasks: [],
|
931
|
+
concurrency: concurrency,
|
932
|
+
saturated: null,
|
933
|
+
empty: null,
|
934
|
+
drain: null,
|
935
|
+
started: false,
|
936
|
+
paused: false,
|
937
|
+
push: function (data, callback) {
|
938
|
+
_insert(q, data, false, callback);
|
939
|
+
},
|
940
|
+
kill: function () {
|
941
|
+
q.drain = null;
|
942
|
+
q.tasks = [];
|
943
|
+
},
|
944
|
+
unshift: function (data, callback) {
|
945
|
+
_insert(q, data, true, callback);
|
946
|
+
},
|
947
|
+
process: function () {
|
948
|
+
if (!q.paused && workers < q.concurrency && q.tasks.length) {
|
949
|
+
var task = q.tasks.shift();
|
950
|
+
if (q.empty && q.tasks.length === 0) {
|
951
|
+
q.empty();
|
952
|
+
}
|
953
|
+
workers += 1;
|
954
|
+
var next = function () {
|
955
|
+
workers -= 1;
|
956
|
+
if (task.callback) {
|
957
|
+
task.callback.apply(task, arguments);
|
958
|
+
}
|
959
|
+
if (q.drain && q.tasks.length + workers === 0) {
|
960
|
+
q.drain();
|
961
|
+
}
|
962
|
+
q.process();
|
963
|
+
};
|
964
|
+
var cb = only_once(next);
|
965
|
+
worker(task.data, cb);
|
966
|
+
}
|
967
|
+
},
|
968
|
+
length: function () {
|
969
|
+
return q.tasks.length;
|
970
|
+
},
|
971
|
+
running: function () {
|
972
|
+
return workers;
|
973
|
+
},
|
974
|
+
idle: function() {
|
975
|
+
return q.tasks.length + workers === 0;
|
976
|
+
},
|
977
|
+
pause: function () {
|
978
|
+
if (q.paused === true) { return; }
|
979
|
+
q.paused = true;
|
980
|
+
},
|
981
|
+
resume: function () {
|
982
|
+
if (q.paused === false) { return; }
|
983
|
+
q.paused = false;
|
984
|
+
var resumeCount = Math.min(q.concurrency, q.tasks.length);
|
985
|
+
// Need to call q.process once per concurrent
|
986
|
+
// worker to preserve full concurrency after pause
|
987
|
+
for (var w = 1; w <= resumeCount; w++) {
|
988
|
+
async.setImmediate(q.process);
|
989
|
+
}
|
990
|
+
}
|
991
|
+
};
|
992
|
+
return q;
|
993
|
+
};
|
994
|
+
|
995
|
+
async.priorityQueue = function (worker, concurrency) {
|
996
|
+
|
997
|
+
function _compareTasks(a, b){
|
998
|
+
return a.priority - b.priority;
|
999
|
+
}
|
1000
|
+
|
1001
|
+
function _binarySearch(sequence, item, compare) {
|
1002
|
+
var beg = -1,
|
1003
|
+
end = sequence.length - 1;
|
1004
|
+
while (beg < end) {
|
1005
|
+
var mid = beg + ((end - beg + 1) >>> 1);
|
1006
|
+
if (compare(item, sequence[mid]) >= 0) {
|
1007
|
+
beg = mid;
|
1008
|
+
} else {
|
1009
|
+
end = mid - 1;
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
return beg;
|
1013
|
+
}
|
1014
|
+
|
1015
|
+
function _insert(q, data, priority, callback) {
|
1016
|
+
if (!q.started){
|
1017
|
+
q.started = true;
|
1018
|
+
}
|
1019
|
+
if (!_isArray(data)) {
|
1020
|
+
data = [data];
|
1021
|
+
}
|
1022
|
+
if(data.length === 0) {
|
1023
|
+
// call drain immediately if there are no tasks
|
1024
|
+
return async.setImmediate(function() {
|
1025
|
+
if (q.drain) {
|
1026
|
+
q.drain();
|
1027
|
+
}
|
1028
|
+
});
|
1029
|
+
}
|
1030
|
+
_each(data, function(task) {
|
1031
|
+
var item = {
|
1032
|
+
data: task,
|
1033
|
+
priority: priority,
|
1034
|
+
callback: typeof callback === 'function' ? callback : null
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item);
|
1038
|
+
|
1039
|
+
if (q.saturated && q.tasks.length === q.concurrency) {
|
1040
|
+
q.saturated();
|
1041
|
+
}
|
1042
|
+
async.setImmediate(q.process);
|
1043
|
+
});
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
// Start with a normal queue
|
1047
|
+
var q = async.queue(worker, concurrency);
|
1048
|
+
|
1049
|
+
// Override push to accept second parameter representing priority
|
1050
|
+
q.push = function (data, priority, callback) {
|
1051
|
+
_insert(q, data, priority, callback);
|
1052
|
+
};
|
1053
|
+
|
1054
|
+
// Remove unshift function
|
1055
|
+
delete q.unshift;
|
1056
|
+
|
1057
|
+
return q;
|
1058
|
+
};
|
1059
|
+
|
1060
|
+
async.cargo = function (worker, payload) {
|
1061
|
+
var working = false,
|
1062
|
+
tasks = [];
|
1063
|
+
|
1064
|
+
var cargo = {
|
1065
|
+
tasks: tasks,
|
1066
|
+
payload: payload,
|
1067
|
+
saturated: null,
|
1068
|
+
empty: null,
|
1069
|
+
drain: null,
|
1070
|
+
drained: true,
|
1071
|
+
push: function (data, callback) {
|
1072
|
+
if (!_isArray(data)) {
|
1073
|
+
data = [data];
|
1074
|
+
}
|
1075
|
+
_each(data, function(task) {
|
1076
|
+
tasks.push({
|
1077
|
+
data: task,
|
1078
|
+
callback: typeof callback === 'function' ? callback : null
|
1079
|
+
});
|
1080
|
+
cargo.drained = false;
|
1081
|
+
if (cargo.saturated && tasks.length === payload) {
|
1082
|
+
cargo.saturated();
|
1083
|
+
}
|
1084
|
+
});
|
1085
|
+
async.setImmediate(cargo.process);
|
1086
|
+
},
|
1087
|
+
process: function process() {
|
1088
|
+
if (working) return;
|
1089
|
+
if (tasks.length === 0) {
|
1090
|
+
if(cargo.drain && !cargo.drained) cargo.drain();
|
1091
|
+
cargo.drained = true;
|
1092
|
+
return;
|
1093
|
+
}
|
1094
|
+
|
1095
|
+
var ts = typeof payload === 'number' ?
|
1096
|
+
tasks.splice(0, payload) :
|
1097
|
+
tasks.splice(0, tasks.length);
|
1098
|
+
|
1099
|
+
var ds = _map(ts, function (task) {
|
1100
|
+
return task.data;
|
1101
|
+
});
|
1102
|
+
|
1103
|
+
if(cargo.empty) cargo.empty();
|
1104
|
+
working = true;
|
1105
|
+
worker(ds, function () {
|
1106
|
+
working = false;
|
1107
|
+
|
1108
|
+
var args = arguments;
|
1109
|
+
_each(ts, function (data) {
|
1110
|
+
if (data.callback) {
|
1111
|
+
data.callback.apply(null, args);
|
1112
|
+
}
|
1113
|
+
});
|
1114
|
+
|
1115
|
+
process();
|
1116
|
+
});
|
1117
|
+
},
|
1118
|
+
length: function () {
|
1119
|
+
return tasks.length;
|
1120
|
+
},
|
1121
|
+
running: function () {
|
1122
|
+
return working;
|
1123
|
+
}
|
1124
|
+
};
|
1125
|
+
return cargo;
|
1126
|
+
};
|
1127
|
+
|
1128
|
+
var _console_fn = function (name) {
|
1129
|
+
return function (fn) {
|
1130
|
+
var args = _baseSlice(arguments, 1);
|
1131
|
+
fn.apply(null, args.concat([function (err) {
|
1132
|
+
var args = _baseSlice(arguments, 1);
|
1133
|
+
if (typeof console !== 'undefined') {
|
1134
|
+
if (err) {
|
1135
|
+
if (console.error) {
|
1136
|
+
console.error(err);
|
1137
|
+
}
|
1138
|
+
}
|
1139
|
+
else if (console[name]) {
|
1140
|
+
_each(args, function (x) {
|
1141
|
+
console[name](x);
|
1142
|
+
});
|
1143
|
+
}
|
1144
|
+
}
|
1145
|
+
}]));
|
1146
|
+
};
|
1147
|
+
};
|
1148
|
+
async.log = _console_fn('log');
|
1149
|
+
async.dir = _console_fn('dir');
|
1150
|
+
/*async.info = _console_fn('info');
|
1151
|
+
async.warn = _console_fn('warn');
|
1152
|
+
async.error = _console_fn('error');*/
|
1153
|
+
|
1154
|
+
async.memoize = function (fn, hasher) {
|
1155
|
+
var memo = {};
|
1156
|
+
var queues = {};
|
1157
|
+
hasher = hasher || function (x) {
|
1158
|
+
return x;
|
1159
|
+
};
|
1160
|
+
var memoized = function () {
|
1161
|
+
var args = _baseSlice(arguments);
|
1162
|
+
var callback = args.pop();
|
1163
|
+
var key = hasher.apply(null, args);
|
1164
|
+
if (key in memo) {
|
1165
|
+
async.nextTick(function () {
|
1166
|
+
callback.apply(null, memo[key]);
|
1167
|
+
});
|
1168
|
+
}
|
1169
|
+
else if (key in queues) {
|
1170
|
+
queues[key].push(callback);
|
1171
|
+
}
|
1172
|
+
else {
|
1173
|
+
queues[key] = [callback];
|
1174
|
+
fn.apply(null, args.concat([function () {
|
1175
|
+
memo[key] = _baseSlice(arguments);
|
1176
|
+
var q = queues[key];
|
1177
|
+
delete queues[key];
|
1178
|
+
for (var i = 0, l = q.length; i < l; i++) {
|
1179
|
+
q[i].apply(null, arguments);
|
1180
|
+
}
|
1181
|
+
}]));
|
1182
|
+
}
|
1183
|
+
};
|
1184
|
+
memoized.memo = memo;
|
1185
|
+
memoized.unmemoized = fn;
|
1186
|
+
return memoized;
|
1187
|
+
};
|
1188
|
+
|
1189
|
+
async.unmemoize = function (fn) {
|
1190
|
+
return function () {
|
1191
|
+
return (fn.unmemoized || fn).apply(null, arguments);
|
1192
|
+
};
|
1193
|
+
};
|
1194
|
+
|
1195
|
+
async.times = function (count, iterator, callback) {
|
1196
|
+
var counter = [];
|
1197
|
+
for (var i = 0; i < count; i++) {
|
1198
|
+
counter.push(i);
|
1199
|
+
}
|
1200
|
+
return async.map(counter, iterator, callback);
|
1201
|
+
};
|
1202
|
+
|
1203
|
+
async.timesSeries = function (count, iterator, callback) {
|
1204
|
+
var counter = [];
|
1205
|
+
for (var i = 0; i < count; i++) {
|
1206
|
+
counter.push(i);
|
1207
|
+
}
|
1208
|
+
return async.mapSeries(counter, iterator, callback);
|
1209
|
+
};
|
1210
|
+
|
1211
|
+
async.seq = function (/* functions... */) {
|
1212
|
+
var fns = arguments;
|
1213
|
+
return function () {
|
1214
|
+
var that = this;
|
1215
|
+
var args = _baseSlice(arguments);
|
1216
|
+
var callback = args.pop();
|
1217
|
+
async.reduce(fns, args, function (newargs, fn, cb) {
|
1218
|
+
fn.apply(that, newargs.concat([function () {
|
1219
|
+
var err = arguments[0];
|
1220
|
+
var nextargs = _baseSlice(arguments, 1);
|
1221
|
+
cb(err, nextargs);
|
1222
|
+
}]));
|
1223
|
+
},
|
1224
|
+
function (err, results) {
|
1225
|
+
callback.apply(that, [err].concat(results));
|
1226
|
+
});
|
1227
|
+
};
|
1228
|
+
};
|
1229
|
+
|
1230
|
+
async.compose = function (/* functions... */) {
|
1231
|
+
return async.seq.apply(null, Array.prototype.reverse.call(arguments));
|
1232
|
+
};
|
1233
|
+
|
1234
|
+
var _applyEach = function (eachfn, fns /*args...*/) {
|
1235
|
+
var go = function () {
|
1236
|
+
var that = this;
|
1237
|
+
var args = _baseSlice(arguments);
|
1238
|
+
var callback = args.pop();
|
1239
|
+
return eachfn(fns, function (fn, cb) {
|
1240
|
+
fn.apply(that, args.concat([cb]));
|
1241
|
+
},
|
1242
|
+
callback);
|
1243
|
+
};
|
1244
|
+
if (arguments.length > 2) {
|
1245
|
+
var args = _baseSlice(arguments, 2);
|
1246
|
+
return go.apply(this, args);
|
1247
|
+
}
|
1248
|
+
else {
|
1249
|
+
return go;
|
1250
|
+
}
|
1251
|
+
};
|
1252
|
+
async.applyEach = doParallel(_applyEach);
|
1253
|
+
async.applyEachSeries = doSeries(_applyEach);
|
1254
|
+
|
1255
|
+
async.forever = function (fn, callback) {
|
1256
|
+
function next(err) {
|
1257
|
+
if (err) {
|
1258
|
+
if (callback) {
|
1259
|
+
return callback(err);
|
1260
|
+
}
|
1261
|
+
throw err;
|
1262
|
+
}
|
1263
|
+
fn(next);
|
1264
|
+
}
|
1265
|
+
next();
|
1266
|
+
};
|
1267
|
+
|
1268
|
+
// Node.js
|
1269
|
+
if (typeof module !== 'undefined' && module.exports) {
|
1270
|
+
module.exports = async;
|
1271
|
+
}
|
1272
|
+
// AMD / RequireJS
|
1273
|
+
else if (typeof define !== 'undefined' && define.amd) {
|
1274
|
+
define([], function () {
|
1275
|
+
return async;
|
1276
|
+
});
|
1277
|
+
}
|
1278
|
+
// included directly via <script> tag
|
1279
|
+
else {
|
1280
|
+
root.async = async;
|
1281
|
+
}
|
1282
|
+
|
1283
|
+
}());
|