3 ms·
You do it like this (using async): async.eachSeries( players, function(player, playercb) { var valid = false; async.whilst( function
by asaarinen 13y ago
You do it like this (using async):
async.eachSeries(
players,
function(player, playercb) {
var valid = false;
async.whilst(
function() { return !valid; },
function(wcb) {
Ask("What's your name", function(name) {
if( IsValidName(name) ) {
player.name = name;
valid = true;
}
wcb();
});
},
playercb);
},
function() { /* done */ }
);
More lines than the foreach loop, but on the other hand, if this was an operation you wanted to do in parallel instead of sequentially, that'd be impossible with the simple loop construct.