Saturday, 15 April 2017

is there any method in bluebird which works like async.waterfall

I am doing something like this in which first function is dependent dependent on second .

let findOrg = () => {
    return new Promise((resolve, reject) => {
        db.organization.find({
                where: data
            })
            .then(org => {
                return resolve(org);
            }).catch(err => {
                reject(err);
            });
    }); };

let createOrg = org => {
    return new Promise((resolve, reject) => {
        if (org) {
            return resolve(org);
        }
        db.organization.build(data)
            .save()
            .then((org) => {
                return resolve(org);
            }).catch(err => {
                reject(err);
            });
    }); };

findOrg()
    .then(org => { //going to find org
        return createOrg(org); //then going to make org
    }).then(newOrg => {
        res.data(mapper.toModel(newOrg)); //then mapping
    }).catch(err => {
        return res.failure(err);
    });

in both above function findOrg and createOrg new promise (ES6) are created

My ques is -- 1. how we can solve this in Bluebird promise library (in sequence if one function is dependent on other) like

async.waterfall([
function(){},
function(){}],
function(){})

  1. here 2 promises are created .is there any way i


via hardy

No comments:

Post a Comment