약속을 반환하는 함수가 두 개 있으며 catch 문을 사용하여 오류를 잡아서 더 명확하게 만들고 싶습니다.약속을 반환하는 함수에 대한 호출 만들기
코드가 올바른 순서로 비동기 적으로 함수를 호출한다고해도 올바른 방법이라고 생각합니다.
이들은
내 호출은 다음과 같습니다// The text is hopefully the email address and the pin number
fb.verifyEmailPin(text).then(function(reply){
// Set the new state to 'get_city'
fb.setState(FB_ID).then(function(result){
}).catch(function(v) {
// Rejection
// If there was an error then prompt the user to enter again
}); // setState
}).catch(function(err){
});// verifyEmailPin
그리고이 실제 기능 - setState를, 나는 아직 verifyEmailPin 기능에 대한 코드를 작성하지 않은하지만 측면에서 설정 상태와 동일한 구조를 다음과 해결하거나 거절 함.
/*
* Function : setState
* Purpose : Set the state to what every is send in on the parameter
*/
exports.setState = function(fbid,newstate){
var success = 'Y';
return new Promise((resolve, reject) => {
client.hmset(fbid, { 'state': newstate });
// Check that we have set it ok
client.hmget(fbid,'state',function(err,reply){
if (err || reply != newstate) {
return reject(err);
}
return resolve(success);
});
}).catch(function(v) {
});
}
* "코드가 비동기 적으로 올바른 순서로 함수를 호출 않습니다."* -.?. 그래서 문제가 무엇인지 당신은 질문을 한 것으로 보이지 않는다 – nnnnnn