this.windTo(where.phi);
}
} else if (where.isError) {
if (this.state.err) {
this.state.currentErrorStep = where;
this.goTo(where.step);
} else {
nextTick(this.boundUnwind);
}
} else {
if (where.fn) {
where.fn();
nextTick(this.boundUnwind);
} else {
this.beginCleanup(where.state);
this.goTo(where.step);
}
}
} else if (!this.state.isFinished) {
this.state.waiting = 0;
this.state.isFinished = true;
this.finalCallback && this.finalCallback.apply(this.context, this.state.args);
}
};
StateMachine.prototype.pushCleanupAction = function (context, fn, args) {
var self = this;
self.state.unwinding.push({
cleanup: true,
fn: function () {
fn.apply(context, args);
}
});
};
StateMachine.prototype.pushCleanupStep = function (id, afterID) {
this.state.unwinding.push({cleanup: true, step: id, state: this.captureStateVars()});
this.goTo(afterID);
};
StateMachine.prototype.pushErrorStep = function (id, retryID) {
this.state.unwinding.push({isError: true, step: id, retryStep: retryID, unwindPoint: this.state.unwinding.length});
this.goTo(retryID);
};
StateMachine.prototype.beginCleanup = function (state) {
this.state.unwinding.push({restoreState: this.captureStateVars()});
this.restoreStateVars(state);
};