@atomist/automation-client
Version:
Atomist API for software low-level client
34 lines • 978 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Support for ScriptedFlushable operations
*/
class AbstractScriptedFlushable {
constructor() {
this.actions = [];
}
recordAction(action) {
this.actions.push(action);
return this;
}
get dirty() {
return this.actions.length > 0;
}
flush() {
// Save actions, as they may be built up again
const actionsToExecute = this.actions;
this.actions = [];
let me = Promise.resolve(this);
for (const a of actionsToExecute) {
me = me.then(p => {
return a(p).then(_ => p);
});
}
// If there were more actions built up while we went
return (this.actions.length > 0) ?
me.then(r => r.flush()) :
me;
}
}
exports.AbstractScriptedFlushable = AbstractScriptedFlushable;
//# sourceMappingURL=AbstractScriptedFlushable.js.map