Loader.prototype._onLoad = function (resource) { var self = this; // run middleware, this *must* happen before dequeue so sub-assets get added properly asyncEachSeries( this._afterMiddleware, function (fn, next) { fn.call(self, resource, next); }, function () { resource.emit('afterMiddleware', resource); self._numToLoad--; self.progress += self._progressChunk; self.emit('progress', self, resource); if (resource.error) { self.emit('error', resource.error, self, resource); } else { self.emit('load', self, resource); } // do completion check if (self._numToLoad === 0) { self.progress = 100; self._onComplete(); } } ); // remove this resource from the async queue resource._dequeue(); };
function end(_error, _result) { error = _error result = _result eachSeries(stack, function(fn, callback) { if (fn) { fn(error, result, callback) } else { callback() } }, function() { // console.log('COMPLETED:', payload) // console.log('RESULT: ', result) var resultObj = { id: payload.id, jsonrpc: payload.jsonrpc, result: result } if (error != null) { resultObj.error = { message: error.stack || error.message || error, code: -32000 } // respond with both error formats finished(error, resultObj) } else { finished(null, resultObj) } }) }
Loader.prototype._loadResource = function (resource, dequeue) { var self = this; resource._dequeue = dequeue; // run before middleware asyncEachSeries( this._beforeMiddleware, function (fn, next) { fn.call(self, resource, function () { // if the before middleware marks the resource as complete, // break and don't process any more before middleware next(resource.isComplete ? {} : null); }); }, function () { // resource.on('progress', self.emit.bind(self, 'progress')); if (resource.isComplete) { self._onLoad(resource); } else { resource.once('complete', self._onLoad, self); resource.load(); } } ); };
db.findKeys('pad:'+padId+':chat:*', null, function(err, keys) { if (err) { return exitIfErr(err); } // 7. Delete the chat records eachSeries(keys, removeRecord, function(err){ if (err) { return exitIfErr(err); } bar.increment(); return next(); }); });
reader.on("close", () => { eachSeries(beerCollection, (beerData, callback) => { const validationData = validateCreateBeer(beerData); if (validationData.error === null) { createBeer(beerCount, beerData, () => { callback(); }); } else { console.error(beerData.beername, " validation error: ", validationData.error); callback(); } }); });
/** * A listener that will start any necessary services and listeners * * @private * @returns {void} */ _onStarting () { this.stats.start() eachSeries(this.availableTransports(this._peerInfo), (ts, cb) => { // Listen on the given transport this.transport.listen(ts, {}, null, cb) }, (err) => { if (err) { log.error(err) return this.emit('error', err) } this.state('done') }) }
var getPostUpdateCmds = function(repo_path, proc_name, cb) { if (typeof repo_path !== 'string') return cb([]); if (repo_path[repo_path.length - 1] !== '/') repo_path += '/'; var searchForCommands = function(file, callback) { fs.exists(repo_path+file, function(exists) { if (exists) { try { var conf_string = fs.readFileSync(repo_path + file); var data = Common.parseConfig(conf_string, repo_path + file); } catch (e) { console.error(e.message || e); } if (data && data.apps) { eachSeries(data.apps, function(item, callb) { if (item.name && item.name === proc_name) { if (item.post_update && typeof(item.post_update) === 'object') { if (item.exec_timeout) EXEC_TIMEOUT = parseInt(item.exec_timeout); return callb(item.post_update); } else { return callb(); } } else return callb(); }, function(final) { return callback(final); }); } else { return callback(); } } else { return callback(); } }); }; eachSeries(['ecosystem.json', 'process.json', 'package.json'], searchForCommands, function(final) { return cb(final ? final : []); }); };
server.post('/sumologs', function (req, res, next) { console.log('POST /sumologs'); res.send('ok'); var logs = JSON.parse(req.body.logs); console.log('parsing ' + logs.length + ' new logs'); eachSeries( logs, function logHandler (log, callback) { var rawMessage = log.Message; console.log('Raw message: ' + rawMessage); var message = JSON.parse(rawMessage); var nginxLog = message.log; var matches = nginxIpRegex.exec(nginxLog); if (matches !== null) { var ip = matches[1]; console.log('parsed ip: ' + ip); getGeoLocation(ip, function (err, data) { if (err) { console.log('Err parsing geo location: ' + err); return callback(err); } postToSlack(data, nginxLog, function (err) { if (err) { console.log('err posting to slack: '); console.log(err); return callback(err); } callback(); }); }); } else { console.log('No matches for log message: ' + nginxLog); } }, function onLogsParsed (err) { if (err) { console.log('Error handling a log: '); console.log(err); return next(err); } console.log('finished handling one pager access logs'); next(); } ); });
db.sequelize.drop().asCallback(function (err) { if (err) throw err console.info('Tables of %s deleted.', db.sequelize.config.database) const STORAGE = constants.CONFIG.STORAGE eachSeries(Object.keys(STORAGE), function (storage, callbackEach) { const storageDir = STORAGE[storage] rimraf(storageDir, function (err) { console.info('%s deleted.', storageDir) return callbackEach(err) }) }, function () { process.exit(0) }) })
var execCommands = function(repo_path, command_list, cb) { var stdout = ''; eachSeries(command_list, function(command, callback) { stdout += '\n' + command; exec('cd '+repo_path+';'+command, function(code, output) { stdout += '\n' + output; if (code === 0) callback(); else callback('`'+command+'` failed'); }); }, function(err) { if (err) return cb(stdout + '\n' + err); return cb(null, stdout); }); }
getMyCertificate(function (err, cert) { if (err) { logger.error('Cannot read public cert.') return callback(err) } const urls = config.get('network.friends') eachSeries(urls, function (url, callbackEach) { computeForeignPodsList(url, podsScore, callbackEach) }, function (err) { if (err) return callback(err) logger.debug('Pods scores computed.', { podsScore: podsScore }) const podsList = computeWinningPods(urls, podsScore) logger.debug('Pods that we keep.', { podsToKeep: podsList }) makeRequestsToWinningPods(cert, podsList, callback) }) })
retStream._write = (file, enc, _next) => { const next = once(_next) try { const files = prepareFile(file, options) .map((file) => Object.assign({ headers: headers(file) }, file)) writing = true eachSeries( files, (file, cb) => multipart.write(file, enc, cb), (err) => { writing = false if (err) { return next(err) } if (ended) { multipart.end() } next() }) } catch (err) { next(err) } }
eachSeries(projectsInAllCategories, (projectsInOneCategory, categoryCallback) => { eachSeries(projectsInOneCategory, (project, projectCallback) => { let newProject; const a = objectID().toHexString(); const b = objectID().toHexString(); const c = objectID().toHexString(); const r = objectID().toHexString(); const noNumberprojectName = project.projectName.replace(/(\d+)/g, ''); if (noNumberprojectName === 'Instance Mode : Instance Container ') { newProject = new Project({ name: project.projectName, user: user._id, files: [ { name: 'root', id: r, _id: r, children: [a, b, c], fileType: 'folder' }, { name: 'sketch.js', content: '// Instance Mode : Instance Container, please check its index.html file', id: a, _id: a, fileType: 'file', children: [] }, { name: 'index.html', content: project.sketchContent, isSelectedFile: true, id: b, _id: b, fileType: 'file', children: [] }, { name: 'style.css', content: defaultCSS, id: c, _id: c, fileType: 'file', children: [] } ], _id: shortid.generate() }); } else { newProject = new Project({ name: project.projectName, user: user._id, files: [ { name: 'root', id: r, _id: r, children: [a, b, c], fileType: 'folder' }, { name: 'sketch.js', content: project.sketchContent, id: a, _id: a, isSelectedFile: true, fileType: 'file', children: [] }, { name: 'index.html', content: defaultHTML, id: b, _id: b, fileType: 'file', children: [] }, { name: 'style.css', content: defaultCSS, id: c, _id: c, fileType: 'file', children: [] } ], _id: shortid.generate() }); } const assetsInProject = project.sketchContent.match(/assets\/[\w-]+\.[\w]*/g) || project.sketchContent.match(/asset\/[\w-]*/g) || []; assetsInProject.forEach((assetNamePath, i) => { let assetName = assetNamePath.split('assets/')[1]; res.forEach((asset) => { if (asset.name === assetName || asset.name.split('.')[0] === assetName) { assetName = asset.name; } }); if (assetName !== '') { if (i === 0) { const id = objectID().toHexString(); newProject.files.push({ name: 'assets', id, _id: id, children: [], fileType: 'folder' }); // add assets folder inside root newProject.files[0].children.push(id); } const fileID = objectID().toHexString(); newProject.files.push({ name: assetName, url: `https://cdn.jsdelivr.net/gh/processing/p5.js-website@master/src/data/examples/assets/${assetName}`, id: fileID, _id: fileID, children: [], fileType: 'file' }); console.log(`create assets: ${assetName}`); // add asset file inside the newly created assets folder at index 4 newProject.files[4].children.push(fileID); } }); newProject.save((saveErr, savedProject) => { if (saveErr) throw saveErr; console.log(`Created a new project in p5 user: ${savedProject.name}`); projectCallback(); }); }, (categoryErr) => { categoryCallback(); }); }, (examplesErr) => {
this.find({}).exec(function(err, data) { // Iterate over the found elements updating it's children eachSeries(data, _updatedDocument, done); });