function calculateFor2(tier:Tier, attack:ActionType, nonRandom:boolean, done: any){ var i = 0; while(i < neededInstances){ let boundDo = doMoveInLoop2.bind(null, tier, attack, nonRandom); callsToMake.push(boundDo); i++; } async.parallel(callsToMake, function(err, res){ let turnsData = res.map((x) => x[0]); let hpData = [].concat.apply([], res.map((x) => x[1])); let lpData = [].concat.apply([], res.map((x) => x[2])); let fpData = [].concat.apply([], res.map((x) => x[3])); console.log(`${(nonRandom ? "1":"0")};${Tier[tier]};${ActionType[attack]};${stats.mean(turnsData)};${stats.median(turnsData)};${stats.variance(turnsData)};${stats.stdev(turnsData)};${stats.percentile(turnsData, 0.90)};${stats.mean(hpData)};${stats.median(hpData)};${stats.variance(hpData)};${stats.stdev(hpData)};${stats.percentile(hpData, 0.90)};${stats.mean(lpData)};${stats.median(lpData)};${stats.variance(lpData)};${stats.stdev(lpData)};${stats.percentile(lpData, 0.90)};${stats.mean(fpData)};${stats.median(fpData)};${stats.variance(fpData)};${stats.stdev(fpData)};${stats.percentile(fpData, 0.90)}`); res = null; turnsData = null; hpData = null; lpData = null; fpData = null; if(done != null){ done(); } callsToMake = null; }); }
Collections.Tips.findOne({"recipient.id": chatterID, "unregisteredUser": true}, function(err: Error, tip: any) { if (err) { bot.sendMessage(chatterID, reportError(err, "Retrieving tip in +accept")); return; } if (!tip) { bot.sendMessage(chatterID, "There are no pending tips involving you"); return; } async.parallel([ function(callback) { Collections.Tips.update({"_id": tip["_id"]}, {$set: {accepted: true}}, {multi: true}, callback); }, function(callback) { // Delete the autoregistered attribute because that user is now fully registered Collections.Users.update({"id": chatterID}, {$unset: {"autoregistered": ""}}, callback); } ], function(err: Error) { if (err) { bot.sendMessage(chatterID, reportError(err, "async.parallel in +accept")); } bot.sendMessage(chatterID, "Congrats, your tip of " + tip.amount + " Gamerscoins from " + tip.sender.name + " was accepted! Welcome to Gamerscoin next generation Trade community"); bot.sendMessage(chatterID, "You can open up the group chat and double click on my name in the sidebar (with the gold star) to send me commands in the future."); bot.sendMessage(chatterID, "Send '+help' to see all of the available commands."); bot.sendMessage(chatterID, "If you have any questions or suggestions, please start a discussion within the group. RazeTheRoof <*****@*****.**> is this bot's author so send any hate/love mail his way."); }); });
private static load(apis, language, callback) { var mylib = new api.Lib; mylib.build(apis); async.parallel([ (cb) => { mylib.installIfMissing((err) => { if(err) { console.log('Error while installing npm packages.'); console.log(err); } cb(); // Don't show error. }); }, (cb) => { Language.factory(language, cb); }, ], (err, res) => { try { process.nextTick(() => { callback(err, res); }); } catch(e) { console.log(e); console.log(e.stack); } }); return mylib; }
return new Promise<[Array<Devices.Device>, Array<Robots.Robot>, Array<Groups.Group>]>( (resolve, _) => { Async.parallel({ devices: async (cb) => { Devices.devicesAsync(authTokens).then((devices) => { Logger.Log.Info(`obtained ${devices.length} devices...`); devicesLookup = devices; cb(null, devices); }); }, robots: async (cb) => { Robots.robotsAsync(authTokens).then((robots) => { Logger.Log.Info(`obtained ${robots.length} robots...`); robotsLookup = robots; cb(null, robots); }); }, groups: async (cb) => { Groups.groupsAsync(authTokens).then((groups) => { Logger.Log.Info(`obtained ${groups.length} groups...`); groupsLookup = groups; cb(null, groups); }); } }, (err, results) => { // this is to satsify ts' typing checks const devices : Array<Devices.Device> = results["devices"], robots : Array<Robots.Robot> = results["robots"], groups : Array<Groups.Group> = results["groups"]; resolve([devices, robots, groups]); }); });
function getPrices(): void { async.parallel([ function(callback) { // Coinbase BTC/USD price getHTTPPage("https://coinbase.com/api/v1/currencies/exchange_rates", callback); }, function(callback) { // Mintpal DOGE/BTC price getHTTPPage("https://api.mintpal.com/v1/market/stats/DOGE/BTC", callback); } ], function(err: Error, results: any[]): void { if (err) { console.trace(err); return; } try { prices["BTC/USD"] = parseFloat(JSON.parse(results[0])["btc_to_usd"]); prices["DOGE/BTC"] = parseFloat(JSON.parse(results[1])[0].last_price); } catch(e) { return; } prices["DOGE/USD"] = prices["BTC/USD"] * prices["DOGE/BTC"]; // Return to strings with .toFixed(8) prices.LastUpdated = Date.now(); }); }
export function compare(leftPath: string, rightPath: string, callback: CompareCallback): void { async.parallel<FSNode>({ // atom shell incorrectly wraps fs.lstat, so we need to check for null here, first leftNode: callback => leftPath ? readCached(leftPath, callback) : setImmediate(callback), rightNode: callback => rightPath ? readCached(rightPath, callback) : setImmediate(callback), }, (error, {leftNode, rightNode}) => { if (error) return callback(error); if (leftNode && rightNode) { if (leftNode.type == 'directory' && rightNode.type == 'directory') { return compareDirectories(Object.assign(leftNode, {path: leftPath}), Object.assign(rightNode, {path: rightPath}), callback); } else if (leftNode.type == 'file' && rightNode.type == 'file') { if (leftNode.size === rightNode.size) { return callback(null, {left: leftNode, right: rightNode, equal: true}); } } return callback(null, {left: leftNode, right: rightNode, equal: false}); } else if (leftNode) { return callback(null, {left: leftNode, right: null, equal: false}); } else { // if (rightNode) { return callback(null, {left: null, right: rightNode, equal: false}); } }); }
return new Promise<any>((resolve)=>{ async.parallel({ count:function (done) {// 查询数量 MongoModel.count(queryParams).exec(function (err,count) { done(err,count); }); }, records:function (done) { MongoModel.find(queryParams,fileds).skip(start).limit(pageSize).populate(populate).sort(sortParams).exec(function (err, doc) { done(err, doc); }); } },function (err, results) { var count = results.count; $page.pageCount = (count - 1) / pageSize + 1; $page.results = results.records; $page.Total=count; if(!err){ resolve($page); } else { resolve(err); } }) })
function cleanAll(done) { async.parallel([ cleanDist, cleanTest, cleanTmp ], done); }
export function kongGetAllApis(callback: Callback<KongCollection<KongApi>>): void { debug('kongGetAllApis()'); async.parallel({ services: callback => kongGetAllServices(callback), routes: callback => kongGetAllRoutes(callback) }, function (err, results) { if (err) return callback(err); const services = results.services as KongCollection<KongService>; const routes = results.routes as KongCollection<KongRoute>; // Step 1: Build a service id to service map const serviceIdMap = new Map<string, KongService>(); for (let i = 0; i < services.data.length; ++i) { const s = services.data[i]; serviceIdMap.set(s.id, s); } // Step 2: Match the routes to the services const kongApis: KongApi[] = []; for (let i = 0; i < routes.data.length; ++i) { const r = routes.data[i]; if (!serviceIdMap.has(r.service.id)) { warn(`kongGetAllApis: Route ${r.id} with paths ${r.paths} has an unknown service id ${r.service.id}`); continue; } kongApis.push(wicked.kongServiceRouteToApi(serviceIdMap.get(r.service.id), r)); } return callback(null, { data: kongApis }); }); // kongGet('apis?size=1000000', callback); }
function getPrices(): void { async.parallel([ function(callback) { // Coinbase BTC/USD price getHTTPPage("https://coinbase.com/api/v1/currencies/exchange_rates", callback); }, function(callback) { // Mintpal GMC/BTC price getHTTPPage("https://api.comkort.com/v1/public/market/summary?market_alias=gmc_btc", callback); } ], function(err: Error, results: any[]): void { if (err) { reportError(err, "Getting current prices"); return; } try { prices["BTC/USD"] = parseFloat(JSON.parse(results[0])["btc_to_usd"]); prices["GMC/BTC"] = parseFloat(JSON.parse(results[1]).markets["GMC/BTC"].last_price); } catch(e) { return; } prices["GMC/USD"] = prices["BTC/USD"] * prices["GMC/BTC"]; // Return to strings with .toFixed(8) prices.LastUpdated = Date.now(); }); }