約束を返す関数が2つあり、エラーをキャッチするために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