说command_arr.length === 2ES5,如何在一个循环中使用的承诺
当我运行下面的函数device_execute_command。执行的消息顺序是
finish one command
finish one command
has latest state?
has latest state?
我想到的是:
finish one command
has latest state?
finish one command
has latest state?
代码
var device_execute_command = function(command_arr) {
// This is the main loop
var i = 0;
for(i=0; i < command_arr.length; i++) {
var command = command_arr[i];
var command_id = command.command_id;
device_run_single_command(command).then(function(command){
console.log();
console.log("finish one command");
console.log(command);
return is_device_has_latest_state(command);
}).then(function(command_with_condi){
console.log();
console.log("has latest state?");
console.log(command_with_condi);
});
}
}