请问如何将result从bluebird的chain中返回出来
刚刚上手bluebird,请问在下面这种情况下如何将findUser中的user返回出来?
userSchema.statics.signin = function(data){
var user = this.findUser(data);
// Using user and data here...
};
userSchema.statics.findUser = function(data){
this.findOneAsync({ username: data.username })
.then(function(user){
// want to return user
})
.error(function(error){
console.error(error.message);
});
};
官方文档中的例子好像并不适用
var Promise = require("bluebird");
var fs = Promise.promisifyAll(require("fs"));
var baseDir = process.argv[2] || ".";
function writeFile(path, contents) {
var fullpath = require("path").join(baseDir, path);
return fs.writeFileAsync(fullpath, contents).thenReturn(fullpath);
}writeFile("test.txt", "this is text").then(function(fullPath) {
console.log("Successfully file at: " + fullPath);
});