使用async/await做同步处理
ES6已经内置支持async和await
var client = require("../../client/greeter_client.js");
var pubfunc = require("../../public/javascripts/pubfunc.js");
var message = require('../../client/generate/secondary_password_check_pb.js');
function secondary_password_check(userName, password) {
return new Promise((resolve, reject)=>{
try {
var request = new message.reqData();
request.setUserName(userName);
var decodePassword = Buffer.from(password, 'base64').toString('ascii');
request.setPassword(decodePassword);
client.secondaryPasswordCheck(request, { deadline: pubfunc.getClientTimeout() }, function (err, response) {
if (err) {
console.log(err);
return false;
}
resolve(response.toObject().result);
});
} catch (error