Hello,
So I need to loop over a bunch of cockpit.spawns, but after each one is
done I need to print a success message
for (var attr in mods){
var cmd = [DSCONF, '-j', 'ldapi://%2fvar%2frun%2f' + server_id +
'.socket','config', 'replace'];
cmd.push(attr + "=" + mods[attr]);
cockpit.spawn(cmd, { superuser: true, "err":
"message"}).done(function() {
// Success update config_value dict
config_values[attr] = mods[attr];
console.log("Success for: " + attr); // But attr is now
different!!!!!!
}).fail(function(data) {
// Log error and reset the html
popup_err("Error", "Failed to update attribute: " + attr +
"\n\n" + data);
$("#" + attr).val(config_values[attr]);
});
}
The problem is that when the first promise finishes "attr" has already
changed. Is there a way to pass/store a copy of "attr" to the spawn()
command so that it can be accessed in done() & fail()? I'm not seeing
anything in the docs to do this, but figured I'd ask.
Thanks,
Mark