jeudi 2 avril 2015

Bluebird type error: expecting an array, promise or thenable

I don't know if I'm not using the .spread method correctly while working with Bluebird promises on Sails.js models. Here's what I have:



transactionAsync('BEGIN')
.then(function() {
return Model.findOne({ id: 5) });
})
.then(function(results){
if(!results) {
return res.notFound();
}
crypto.randomBytes(24, function(err, buf) {
if(err) throw new Error(err);
var token = buf.toString('hex');
// This is where it fails
return [results, token];
});
})
.spread(function(results, token) {
// It doesn't get to log these
console.log(results, token);
...
});


After returning [results, token] on the second .then (inside of the crypto callback), it spits out



[TypeError: expecting an array, a promise or a thenable]


I removed the rest of the code after .spread, since it's not really relevant, and that's where execution stops before returning an error.


I just want to pass variables results and token to the function inside of .spread. What am I doing wrong?


Any help is great. Thanks.


Aucun commentaire:

Enregistrer un commentaire