我有这段代码,我并不十分不满意,但想知道如何转换为反应范式而不是在ES7中使用async / await(因为我知道如何做到这一点,我认为)。 请原谅代码中的注释,一旦调试完成,我通常会把它们拿出来。我正在使用async.js希望它能带给我像async / await这样的东西,但不会。此外,如果有人知道javascript中类似的CountDownLatch impl,我将有兴趣了解它。
document.getElementById('submitLoginBtn').addEventListener("click", function () {
var rqid = nextReqId();
async.series([
function(callback) {
console.log("Generating password for reqid: " + rqid);
genPartOfRequest(callback);
},
function(callback) {
console.log("Adding listener for " + msg_LogonResponse + " and reqid: " + rqid);
mHandler.addListener(msg_LogonResponse, rqid, function(msg) {
console.log("Listener callback called for " + msg_LogonResponse + " and reqid: " + rqid);
if (isOk(msg)) {
postLogin(msg);
}
callback(null);
});
console.log("Sending logon request for " + msg_LogonRequest + " and reqid: " + rqid);
logon(msg_LogonRequest, rqid);
},
function(callback) {
console.log("Removing listener for " + msg_LogonResponse + " and reqid: " + rqid);
mHandler.removeListener(msg_LogonResponse, rqid);
callback(null);
}
]);
});
由于 d