How to use the join function from bluebird

Find comprehensive JavaScript bluebird.join code examples handpicked from public code repositorys.

bluebird.join is a method in the Bluebird Promise library that allows you to execute multiple promises in parallel and returns a promise that resolves with an array of their resolved values.

41
42
43
44
45
46
47
48
49
50
.then(function (survey) {
  if (!survey) {
    // Cancel the count and bounds promises.
    countPromise.cancel();
    boundsPromise.cancel();
    return Promise.join(countPromise, boundsPromise)
    .then(function () {
      // In case the count or bounds promises resolve before we cancel them.
      res.send(404);
    })
fork icon14
star icon20
watch icon4

+ 3 other calls in file

178
179
180
181
182
183
184
185
186
187
188
        });
    });
}


function buildBrowser(sources, dir, tmpDir, depsRequireCode, minify, npmPackage, license) {
    return Promise.join(dir, tmpDir, npmPackage, license, function(dir, tmpDir, npmPackage, license) {
        return Promise.map(sources, function(source) {
            return jobRunner.run(function() {
                var code = source.source;
                var sourceFileName = source.sourceFileName;
fork icon7
star icon9
watch icon4

+ 3 other calls in file

How does bluebird.join work?

bluebird.join is a method in the Bluebird library for combining the results of multiple promises into a single promise, with the results returned in the order they were passed in as an array.

The first argument of the join method is an array of promises that need to be resolved, and the second argument is a callback function that accepts the resolved values of the promises as arguments and returns the value for the new promise. If any of the promises passed to the join method are rejected, the resulting promise will also be rejected.

111
112
113
114
115
116
117
118
119
120
}

const reqDate = dateUtil.getRequestedDate(req);
const rspDate = req.query.aggregated ? dateUtil.addDays(reqDate, -1) : reqDate;

return BBPromise.join(
    getTopPageviews(req, util.removeTLD(req.params.domain), rspDate),
    si.getSiteInfo(req),
    (pageviewsResponse, siteinfo) => {
        const mainPage = siteinfo.general && siteinfo.general.mainpage;
fork icon2
star icon3
watch icon18

+ 2 other calls in file

459
460
461
462
463
464
465
466
467
468

var p1 = resolved('p1')
var p2 = resolved('p2')
var p3 = resolved('p3')

Promise.join(p1, p2, p3, function (a, b, c) {
  t.strictEqual(a, 'p1')
  t.strictEqual(b, 'p2')
  t.strictEqual(c, 'p3')
  t.strictEqual(ins.currTransaction().id, trans.id)
fork icon1
star icon0
watch icon1

+ 2 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const Promise = require("bluebird");

const getUserDetails = (userId) => {
  // simulate a database call that returns user details
  return Promise.delay(1000).then(() => {
    return {
      id: userId,
      name: "John",
      age: 30,
      city: "New York",
    };
  });
};

const getOrders = (userId) => {
  // simulate a database call that returns user orders
  return Promise.delay(500).then(() => {
    return [
      { id: 1, user_id: userId, amount: 10 },
      { id: 2, user_id: userId, amount: 20 },
      { id: 3, user_id: userId, amount: 30 },
    ];
  });
};

Promise.join(getUserDetails(123), getOrders(123), (userDetails, orders) => {
  console.log("User details:", userDetails);
  console.log("Orders:", orders);
});

In this example, getUserDetails and getOrders are two functions that return promises. We use Promise.join to execute these functions in parallel and get their results. When both promises are resolved, the then callback is called with the results of both promises.

258
259
260
261
262
263
264
265
266
267

const removePragmas = rollupPluginStripPragma({
  pragmas: ["debug"],
});

const promise = Promise.join(
  rollup
    .rollup({
      input: "Specs/SpecList.js",
      plugins: [externalCesium],
fork icon0
star icon1
watch icon1

+ 5 other calls in file

1080
1081
1082
1083
1084
1085
1086
1087
1088
      return result.toJSON().map(function(row) {
        return row.id;
      });
    });

  return Promise.join(asc, desc).then(function(results) {
    expect(results[0].reverse()).to.eql(results[1]);
  });
});
fork icon0
star icon1
watch icon1

+ 3 other calls in file

191
192
193
194
195
196
197
198
199
200

async function updateSchedule(headers, payloadData) {
  const lang = headers['content-language'];
  try {
    // eslint-disable-next-line
    const preCondition = Promise.join(checkTime(payloadData), checkSP(headers, payloadData), (checkTimeData, checkSPdata) => {
      if (checkTimeData) {
        throw Boom.rangeNotSatisfiable(configs.MessageConfiguration.get('/lang', { locale: lang, message: 'INVALID_TIME_RANGE' }));
      }
    });
fork icon0
star icon0
watch icon1

+ 13 other calls in file

199
200
201
202
203
204
205
206
207
208
209
}


function save (dir, pkginfo, opts, cb) {
  // copy the keys over in a well defined order
  // because javascript objects serialize arbitrarily
  BB.join(
    checkPackageFile(dir, SHRINKWRAP),
    checkPackageFile(dir, PKGLOCK),
    checkPackageFile(dir, 'package.json'),
    (shrinkwrap, lockfile, pkg) => {
fork icon0
star icon0
watch icon1

83
84
85
86
87
88
89
90
91
92
_.unset(module, 'keepOutputDirectory');

return expect(prepareRun())
  .resolves.toBeUndefined()
  .then(() =>
    BbPromise.join(
      expect(module.originalServicePath).toEqual(servicePath),
      expect(module.originalRspackOutputPath).toEqual(rspackOutputPath),
      expect(module.keepOutputDirectory).toBe(true),
      expect(serverless.config.servicePath).toEqual(
fork icon0
star icon0
watch icon0

+ 3 other calls in file

3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
    return req.on('aborted', () => {
      return resolve()
    })
  })

  return Promise.join(aborted, closed)
  .then(() => {
    return done()
  })
}
fork icon0
star icon0
watch icon0

+ 5 other calls in file