我有func1
函数返回承诺。在func2
我已经开始承诺链。 我想在这里做的是,我想在旧承诺链中使用func1
解析消息,并且我希望此代码不那么复杂。什么是加盟func1
承诺通过增加一个额外的步骤,以老许链答应链func2
如何加入对承诺链的承诺
var func1 = function(){
return new promise(function(resolve, reject){
//some operations here
});
};
var func2 = function(){
promise.resolve(someFuncSync())
.then(function(){
//this is the old promise chain
func1()
.then(function(message,error){
return message;
//i want use this return value in old promise chain
});
console.log(message);
//printing func1 returned message in old promise chain
})
};
你不能做到这一点,你可以访问只在'then' func1中发送消息。 – Grundy
@JonathanLonowski你应该发布它作为答案。只需使用'then(function(message){console.log(message)})'。 – dfsq
“链”是什么意思?序列?你想分别用func1和func2的解析值做什么? –