How to use the mapSeries function from bluebird
Find comprehensive JavaScript bluebird.mapSeries code examples handpicked from public code repositorys.
bluebird.mapSeries is a function in the Bluebird library that maps over an array in series, resolving each item before moving on to the next.
GitHub: mergestat/mergestat
84 85 86 87 88 89 90 91 92 93
const createSync = ` INSERT INTO mergestat.container_syncs (repo_id, image_id) VALUES ($1, $2) ON CONFLICT (repo_id, image_id) DO UPDATE SET repo_id = EXCLUDED.repo_id, image_id = EXCLUDED.image_id RETURNING id`; // we iterate over each repository, creating a sync and a schedule yield bluebird.mapSeries(repos, (repo) => __awaiter(this, void 0, void 0, function* () { const { rows: syncs } = yield pg.query(createSync, [repo.id, args.image]); yield pg.query('INSERT INTO mergestat.container_sync_schedules (sync_id) VALUES ($1) ON CONFLICT DO NOTHING', [syncs[0].id]); })); return true;
268 269 270 271 272 273 274 275 276 277 278 279
async function _createComplementaryCertificationHability( { complementaryCertifications, certificationCandidateId, userId, organizationLearnerId }, databaseBuilder ) { return bluebird.mapSeries(complementaryCertifications, async (key) => { const { id: complementaryCertificationId } = await knex('complementary-certifications').where({ key }).first(); databaseBuilder.factory.buildComplementaryCertificationSubscription({ complementaryCertificationId,
+ 15 other calls in file
How does bluebird.mapSeries work?
bluebird.mapSeries is a function provided by the Bluebird promise library in JavaScript that takes an array and a function, then applies the function to each element in the array in series (one after another) and returns a promise that resolves to an array of the results. If any of the promises returned by the function are rejected, the resulting promise will be rejected with that reason.
30 31 32 33 34 35 36 37 38 39 40
'ign-api-gestion', 'cadastre', 'ftth' ] return bluebird.mapSeries(multiSourcesInputs, async sourceName => { const data = await getSourceData(sourceName, codeCommune) return {...data, source: sourceName} }) }
+ 2 other calls in file
877 878 879 880 881 882 883 884 885 886
var p3 = resolved(3) var arr = [p2, p3, p1] var results = [2, 3, 1] var i = 0 Promise.mapSeries(arr, function (item, index, length) { var expected = results.shift() t.strictEqual(item, expected) t.strictEqual(index, i++) t.strictEqual(length, 3, 'length should be 3')
+ 2 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11
const Promise = require("bluebird"); const nums = [1, 2, 3, 4, 5]; Promise.mapSeries(nums, (num) => { return Promise.delay(1000).then(() => { console.log(num); }); }).then(() => { console.log("Done!"); });
In this example, we use bluebird.mapSeries to iterate over an array of numbers and print them out one at a time with a delay of one second between each number. Once all numbers have been printed, the final message "Done!" is logged to the console.
356 357 358 359 360 361 362 363 364 365
* @return {Promise} */ remove(callback) { const model = this._model; return Promise.mapSeries(this.data, item => model.removeById(item._id)).asCallback(callback); } /** * Populates document references.
+ 19 other calls in file
185 186 187 188 189 190 191 192 193 194
* @param {function} [callback] * @return {Promise} */ insert(data, callback) { if (Array.isArray(data)) { return Promise.mapSeries(data, item => this.insertOne(item)).asCallback(callback); } return this.insertOne(data, callback); }
+ 9 other calls in file
GitHub: tratatun/node-learn
5 6 7 8 9 10 11 12 13 14 15 16
const Products = require('../models/products'); chai.use(chaiHttp); const setup = (...products) => { return BlueBird.mapSeries(products, user => { return chai.request(server) .post('/products') .send(user) .then(response => {
+ 10 other calls in file
188 189 190 191 192 193 194 195 196 197 198
function rebuildBucket (cache, bucket, stats, opts) { return fs.truncateAsync(bucket._path).then(() => { // This needs to be serialized because cacache explicitly // lets very racy bucket conflicts clobber each other. return BB.mapSeries(bucket, entry => { const content = contentPath(cache, entry.integrity) return fs.statAsync(content).then(() => { return index.insert(cache, entry.key, entry.integrity, { uid: opts.uid,
160 161 162 163 164 165 166 167 168 169 170
var bluebird = require("bluebird"); bluebird.mapSeries(source, x => sink(x)); // NOT OK (for taint-tracking configs) const foo = bluebird.mapSeries(source, x => x); sink(foo); // NOT OK (for taint-tracking configs) })
bluebird.reject is the most popular function in bluebird (2988 examples)