【发布时间】:2017-12-12 00:21:26
【问题描述】:
我正在使用 Promise,但我遇到了异步递归 Promise 的问题。
场景是我需要检查函数内部的令牌验证,如果令牌过期,我需要再次调用该函数。 以下是我到目前为止所做的代码:
module.exports={
frstFun:()=>{...
},
secondFun:(param)=>{
return new Promise((resolve,reject)=>{
request({
url:url+'myapi',
qs:{q:param,acc_token:token},
method:'GET',
},function(err,response,body){
if(error){
//here i need to call secondFun() method..
}
});
})
}
};
我尝试调用 this.secondFun() 但它给出错误 secondFun() is not a method.
【问题讨论】:
-
对于那种事情,也许 observables 是一种方法,而不是 retrywhen 也许xgrommx.github.io/rx-book/content/getting_started_with_rxjs/…
标签: javascript node.js typescript recursion promise