How to use the promisify function from bluebird

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

16
17
18
19
20
21
22
23
24
25

const log = require('./logger.js')(__filename);
const Config = require('./config.js');
const Promise = require('bluebird');
const cp = require('child_process');
const execAsync = Promise.promisify(cp.exec);
const fs = require('fs');
const readFileAsync = Promise.promisify(fs.readFile);
const writeFileAsync = Promise.promisify(fs.writeFile);
const sem = require('../sensor/SensorEventManager.js').getInstance();
fork icon117
star icon469
watch icon48

+ 11 other calls in file

16
17
18
19
20
21
22
23
24
25
// Init //
//------//

const cliLog = utils.cliLog,
  createMadonnaFn = madonnaFunction.create,
  execAsync = bPromise.promisify(child_process.exec),
  isSqliteFileSync = common.isSqliteFileSync,
  marg = getGenerateSkeletonMarg()

//------//
fork icon18
star icon371
watch icon6

972
973
974
975
976
977
978
979
980
981
 *  "running" - if the docker container exists and is running
 * diskSpace:
 *  .virtualBytes - size of the container's flattened images in bytes, if container exists, null otherwise
 *  .realBytes - size of the container's own RW layer in bytes, if container exists, null otherwise
 */
Server.prototype.updateBuildContainerStatus = Promise.promisify(function(build, done) {
  var self = this;
  var container = new Container({
    docker: this.config.docker,
    containerId: build.container.id,
fork icon25
star icon77
watch icon28

+ 8 other calls in file

29
30
31
32
33
34
35
36
37
38
};

exports.get = function get(req, res) {
  var surveyId = req.params.surveyId;

  var countPromise = Promise.promisify(Response.countEntries, Response)({
    'properties.survey': surveyId
  }).cancellable();

  var boundsPromise = Promise.promisify(Response.getBounds, Response)(surveyId).cancellable();
fork icon14
star icon20
watch icon4

+ 3 other calls in file

13
14
15
16
17
18
19
20
21
22
//      console.log('done!');
// })

var co = require('co');
var bb = require('bluebird');
var handleAsync = bb.promisify(handle);
co(function *() {
        var elems = [1,2,3,4,5];
        var promises = []
        for (var i = 0; i < elems.length; i++) {
fork icon4
star icon17
watch icon4

+ 13 other calls in file

-3
fork icon3
star icon12
watch icon0

+ 5 other calls in file

0
1
2
3
4
5
6
7
8
9
var Promise = require("bluebird");
var path = require("path");
var jobRunner = require("./job-runner/job-runner.js");
Promise.longStackTraces();
var utils = require("./utils.js");
var glob = Promise.promisify(require("glob"));
var fs = Promise.promisifyAll(require("fs"));
var mkdirp = Promise.promisify(require("mkdirp"));
var rimraf = Promise.promisify(require("rimraf"));

fork icon7
star icon9
watch icon4

+ 7 other calls in file

1
2
3
4
5
6
7
8
9
10

var path = require('path');
var _ = require('lodash');
var Promise = require('bluebird');
var fs = Promise.promisifyAll(require('fs'));
var execAsync = Promise.promisify(require('child_process').exec);
var program = require('commander');
var request = require('request');
var pkg = require('../package.json');
var Spec = require('../lib/Spec');
fork icon2
star icon4
watch icon37

+ 9 other calls in file

15
16
17
18
19
20
21
22
23
24

'use strict';

const Bluebird = require('bluebird');
const childProcess = require('child_process');
const isElevated = Bluebird.promisify(require('is-elevated'));
const ipc = require('node-ipc');
const _ = require('lodash');
const os = require('os');
const path = require('path');
fork icon0
star icon178
watch icon23

+ 9 other calls in file

2
3
4
5
6
7
8
9
10
11
12
13


const getLoggedInAgent = require('../../helpers/getLoggedInAgent');
const dbService = require('../../../../server_scripts/services/db');
const promise = require('bluebird');
const getUserPr = promise.promisify(dbService.findDB);
const getOrdersPr = promise.promisify(dbService.findDB);
const chance = new Chance();


before(done => {
  if (typeof app === 'undefined') {
fork icon1
star icon20
watch icon6

+ 3 other calls in file

2
3
4
5
6
7
8
9
10
11
12
13


const getLoggedInAgent = require('../../helpers/getLoggedInAgent');
const dbService = require('../../../../server_scripts/services/db');
const promise = require('bluebird');
const getUserPr = promise.promisify(dbService.findDB);
const insertUserPr = promise.promisify(dbService.insertDB);


const chance = new Chance();
let user;

fork icon1
star icon20
watch icon6

+ 3 other calls in file

2
3
4
5
6
7
8
9
10
11
12
13


const getLoggedInAgent = require('../../helpers/getLoggedInAgent');
const dbService = require('../../../../server_scripts/services/db');
const promise = require('bluebird');
const getUserPr = promise.promisify(dbService.findDB);
const getDiscountPr = promise.promisify(dbService.findDB);
const insertUserPr = promise.promisify(dbService.insertDB);


const chance = new Chance();

fork icon1
star icon20
watch icon6

+ 5 other calls in file

9
10
11
12
13
14
15
16
17
18
// Import services
const update = require('../services/user').update;
const fixObject = require('../services/user').fixObject;
const dbUtils   = require('../services/dbUtils');
const dbService = require('../services/db');
const updateOrInsertAllEntriesPr = promise.promisify(dbUtils.updateOrInsertAllEntries);
const getUserPr = promise.promisify(dbService.findDB);
const insertUserPr = promise.promisify(dbService.insertDB);
const hash      = require('../services/security').hash;

fork icon1
star icon20
watch icon6

+ 5 other calls in file

6
7
8
9
10
11
12
13
14
15
16
17
var log = require("npmlog");
var querystring = require("querystring");
var url = require("url");


function setProxy(url) {
    if (typeof url == undefined) return request = bluebird.promisify(require("request").defaults({ jar: true }));
    return request = bluebird.promisify(require("request").defaults({ jar: true, proxy: url }));
}


function getHeaders(url, options, ctx, customHeader) {
fork icon3
star icon7
watch icon2

+ 98 other calls in file

5
6
7
8
9
10
11
12
13
14
15
16
17


var fs = require('fs');
var bluebird = require("bluebird");


console.time('xx');
var readFileAsync = bluebird.promisify(fs.readFile);
console.timeEnd('xx');


readFileAsync("part01/bad.json")
  .then(function (val) {
fork icon3
star icon2
watch icon1

66
67
68
69
70
71
72
73
74
75
        .bold(bracketName).add('was not found').e)
}

let doc = new GoogleSpreadsheet(sheetId);
let info;
const getInfo = Promise.promisify(doc.getInfo);
try {
    info = await getInfo();
} catch (e) {
    this.log.error(e);
fork icon1
star icon3
watch icon0

16
17
18
19
20
21
22
23
24
25
26
global.THREE = require('three')
var createOrbitViewer = require('three-orbit-viewer')(THREE)
var createText = require('../')
var Promise = require('bluebird')
var Shader = require('../shaders/multipage')
var loadFont = Promise.promisify(require('load-bmfont'))


// parallel load our font / textures
Promise.all([
  loadFont('fnt/Norwester-Multi-64.fnt'),
fork icon0
star icon6
watch icon1

+ 13 other calls in file

-3
fork icon0
star icon2
watch icon2

+ 11 other calls in file

277
278
279
280
281
282
283
284
285
286

Example of using a predicate-based filter:

```js
var Promise = require("bluebird");
var request = Promise.promisify(require("request"));

function ClientError(e) {
    return e.code >= 400 && e.code < 500;
}
fork icon0
star icon2
watch icon2