原帖GitHub
您好,
您能告诉我如何使用蓝鸟从自定义函数返回承诺吗?以下是我正在使用的内容:
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var P = require('bluebird');
var redisSessionStore = new RedisStore({client: redisClient});
P.promisifyAll(redisSessionStore);
redisSessionStore.getAsync('active_session').then(function(data) {
if(!data || (data.timestamp < Data.now())) {
return sulogin(params);
}
}).then(function(values) { // expecting sulogin to return a promise
// do another async call
});
function sulogin(params){
}
如何让sulogin回复承诺?
答案 0 :(得分:-1)
我修改了sulogin看起来像这样:
var http = require('http');
var Promise = require('bluebird');
function sulogin(arg, fn) {
Promise.props({
host:"localhost",
port: 8080,
path: '/uaa/login.do',
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function(result) {
return http.requestAsync(result);
});
}