Node.js sails.js waterline bluebird. then and.pread

I am trying to figure out how promises work in sails and have successfully passed the data transfer from the request waterlines through. then but couldn't use .spread. I am getting a function not defined error. Any suggestions on how the first section of code can be improved?

 //results in error
    Promise.all([Xyz.find(), Abc.find()]).spread(function (someOtherResult, yetAnotherResult) {
        console.log(someOtherResult)
    }).catch(function (err) {
        console.log(err);
    })

      

Next work, but it will be harder to fetch data or require overly long nested ones. then clauses:

    Promise.all([Xyz.find(), Abc.find()]).then(function (results) {
        console.log(results[0][1]);
        console.log(results[0].length);
    })


    Abc.find().then(function (foundAbcs) {
        Promise.all(Xyz.find().then(function (foundXyzs) {
            console.log(foundAbcs);
            console.log(foundXyzs);
            // additional syncranouse logic with Abc and Xyz
        }))
    })

      

+3


source to share


1 answer


Ok, very simple error, I didn't understand what I needed:

var Promise = require ('bluebird');



to the version of module.exports in sails.js.11, the problem is resolved.

+2


source







All Articles