_.fill(urls, config.test.mirror); const chunks = _.chunk(urls, 50); const result = new Array(chunks.length);
constructor(tickerRepository) { this.trottle = {}; setInterval(async () => { const tickers = Object.values(this.trottle); this.trottle = {}; if (tickers.length > 0) { for (const chunk of _.chunk(tickers, 100)) { await tickerRepository.insertTickers(chunk); } } }, 1000 * 15); }
// 将 ZRANGE 的结果解析为 {ranking, userId, score} 这样的对象 function parseLeaderboard(leaderboard) { return _.chunk(leaderboard, 2).map(function(item, index) { return { ranking: index + 1, userId: item[0], score: parseInt(item[1]) } }) }
async bulkAddTasks(tasks: Task[], chunkSize = 100): Promise<string[]> { if (!this._redis) { this._connect(); } const chunks = lodash.chunk(tasks, chunkSize); let result = []; for (const c of chunks) { const pipeline = this._redis!.pipeline(); for (const t of c) { const { data = null, dedupKey = null } = t; pipeline.enqueue(this.qname, this._DEDUPSET, JSON.stringify(data), dedupKey, 0); } const retval = await pipeline.exec(); result.push(retval); } result = this._flatDeep(result).filter(i => !!i); return result; }
// calling APIs const getPastTimeStamps = () => { const dates = [] for (let i = daysOfData; i > -1; i--) { dates.push(moment().subtract(i, 'days').unix()) } return _.chunk(dates, 15) }
function cat(...predicates) { const pairs = _.chunk(predicates, 2); return { op: 'cat', conform: _.partial(_conform, pairs), unform: values => _.map(pairs, ([k, p]) => unform(p, values[k])), gen: () => tcg.array(_.map(pairs, ([, p]) => gen(p))), describe: () => [cat.name, ...describe(predicates)], explain: function*(values, {via}) { yield* explainInsufficientInput(values, pairs, via); yield* explainExtraInput(pairs, values, via); yield* explainInvalid(values, pairs, via); } }; }
function alt(...predicates) { const pairs = _.chunk(predicates, 2); return { op: 'alt', conform: ([value]) => { const found = _.find(pairs, ([, predicate]) => isValid(predicate, value)); return _.isUndefined(found) ? invalidString : [found[0], value]; }, gen: () => tcg.null.then(() => { const result = gen(_.sample(pairs)[1]); return tcg.array(result, {size: 1}); }), describe: () => [alt.name, ...describe(predicates)], explain: function*(value, {via}) { yield* explainInsufficientInput(predicates, value, via); yield* explainExtraInput(predicates, value, via); yield* explainInvalid(value, pairs, via); } }; }
const Excute = async function(User, sleep){ try { console.log(chalk`\n{yellow [?] Try to Login . . .}`); const doLogin = await Login(User); console.log(chalk`{green [!] Login Succsess}, {yellow [?] Try Like All Media in Feed / Timeline . . .\n}`); const feed = new Client.Feed.Timeline(doLogin.session); var cursor; do { if (cursor) feed.setCursor(cursor); var media = await feed.get(1); media = _.chunk(media, 10); for (var i = 0; i < media.length; i++) { await Promise.all(media[i].map(async (media) => { const doLike = await Like(doLogin.session, media); console.log(chalk`[{bold.green Username:}] ${media.params.user.username}\n[{cyan ${media.id}}] => [${doLike}]`); })) await console.log(chalk`{yellow \n [#][>] Delay For ${sleep} MiliSeconds [<][#] \n}`); await delay(sleep); } } while(feed.isMoreAvailable()); } catch (err) { console.log(err); } }
async.each(_.chunk(commands, 100), function(chunk, callback) { client.mset(chunk, callback); },done);
function or(...predicates) { const pairs = _.chunk(predicates, 2); return { conform: value => { const found = _.find(pairs, ([, predicate]) => predicate(value)); return _.isUndefined(found) ? invalidString : [found[0], value]; }, unform: ([key, value]) => { const found = _.find(pairs, ([k]) => k === key); if (_.isUndefined(found)) { throw new Error(`Key ${key} does not exist in spec`); } return value; }, gen: () => _.isEmpty(predicates) ? tcg.null : tcg.null.then(() => gen(_.sample(pairs)[1])), describe: () => [or.name, ...describe(predicates)], explain: function*(value, {via}) { const problems = _.map(pairs, ([k, predicate]) => explainData(predicate, value, {path: [k], via})); if (!_.some(problems, _.isNull)) { for (let p of problems) { yield p.problems[0]; } } } }; }
if (TargetCursor) Targetfeed.setCursor(TargetCursor); var TargetResult = await Targetfeed.get(); TargetResult = _.chunk(TargetResult, accountsPerDelay); for (let i = 0; i < TargetResult.length; i++) { var timeNow = new Date();
async _loadMailSummariesAndEmitAsEvents() { // UID: Unique id of a message. const uids = await this._getAllUids() const newUids = uids.filter(uid => !this.loadedUids.has(uid)) // Optimize by fetching several messages (but not all) with one 'search' call. // fetching all at once might be more efficient, but then it takes long until we see any messages // in the frontend. With a small chunk size we ensure that we see the newest emails after a few seconds after // restart. const uidChunks = _.chunk(newUids, 20) // Creates an array of functions. We do not start the search now, we just create the function. const fetchFunctions = uidChunks.map(uidChunk => () => this._getMailHeadersAndEmitAsEvents(uidChunk) ) await pSeries(fetchFunctions) if (!this.initialLoadDone) { this.initialLoadDone = true this.emit(ImapService.EVENT_INITIAL_LOAD_DONE) } }
/** * Converts `funcNames` into a chunked list string representation. * * @private * @param {string[]} funcNames The function names. * @returns {string} Returns the function list string. */ function toFuncList(funcNames) { let chunks = _.chunk(funcNames.slice().sort(), 5); let lastChunk = _.last(chunks); const lastName = lastChunk ? lastChunk.pop() : undefined; chunks = _.reject(chunks, _.isEmpty); lastChunk = _.last(chunks); let result = '`' + _.map(chunks, chunk => chunk.join('`, `') + '`').join(',\n`'); if (lastName == null) { return result; } if (_.size(chunks) > 1 || _.size(lastChunk) > 1) { result += ','; } result += ' &'; result += _.size(lastChunk) < 5 ? ' ' : '\n'; return result + '`' + lastName + '`'; }
constructor(candlestickRepository) { this.candlestickRepository = candlestickRepository; this.trottle = {}; this.promises = []; setInterval(async () => { const candles = Object.values(this.trottle); this.trottle = {}; const promises = this.promises.slice(); this.promises = []; // on init we can have a lot or REST api we can have a lot of candles // reduce database locking time by split them if (candles.length > 0) { for (const chunk of _.chunk(candles, 1000)) { await this.insertCandles(chunk); } } promises.forEach(resolve => { resolve(); }); }, 1000 * 5); }
/* * 获取my app */ async getMyappList(page = 1) { page = page > 1 ? page : 1; let list = []; const all = this.fileSyncInstance() .get('my_app') .value(); if (all.length > 0) { const listPage = _.chunk(all, 10); const listInfo = listPage[page - 1]; list = _.map(listInfo, 'appid'); } return list; }