'Register' and 'Fork' now play well together.
This commit is contained in:
parent
f091918575
commit
8e6763c165
@ -52,14 +52,23 @@ const FlowControl = {
|
|||||||
output = "",
|
output = "",
|
||||||
progress = 0;
|
progress = 0;
|
||||||
|
|
||||||
|
state.forkOffset += state.progress + 1;
|
||||||
|
|
||||||
recipe.addOperations(subOpList);
|
recipe.addOperations(subOpList);
|
||||||
|
const ingValues = subOpList.map(op => op.getIngValues());
|
||||||
|
|
||||||
// Run recipe over each tranche
|
// Run recipe over each tranche
|
||||||
for (i = 0; i < inputs.length; i++) {
|
for (i = 0; i < inputs.length; i++) {
|
||||||
log.debug(`Entering tranche ${i + 1} of ${inputs.length}`);
|
log.debug(`Entering tranche ${i + 1} of ${inputs.length}`);
|
||||||
|
|
||||||
|
// Baseline ing values for each tranche so that registers are reset
|
||||||
|
subOpList.forEach((op, i) => {
|
||||||
|
op.setIngValues(ingValues[i]);
|
||||||
|
});
|
||||||
|
|
||||||
const dish = new Dish(inputs[i], inputType);
|
const dish = new Dish(inputs[i], inputType);
|
||||||
try {
|
try {
|
||||||
progress = await recipe.execute(dish, 0);
|
progress = await recipe.execute(dish, 0, state);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!ignoreErrors) {
|
if (!ignoreErrors) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -117,7 +126,7 @@ const FlowControl = {
|
|||||||
if (!registers) return state;
|
if (!registers) return state;
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (ENVIRONMENT_IS_WORKER()) {
|
||||||
self.setRegisters(state.progress, state.numRegisters, registers.slice(1));
|
self.setRegisters(state.forkOffset + state.progress, state.numRegisters, registers.slice(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,11 +141,14 @@ Recipe.prototype.lastOpIndex = function(startIndex) {
|
|||||||
*
|
*
|
||||||
* @param {Dish} dish
|
* @param {Dish} dish
|
||||||
* @param {number} [startFrom=0] - The index of the Operation to start executing from
|
* @param {number} [startFrom=0] - The index of the Operation to start executing from
|
||||||
|
* @param {number} [forkState={}] - If this is a forked recipe, the state of the recipe up to this point
|
||||||
* @returns {number} - The final progress through the recipe
|
* @returns {number} - The final progress through the recipe
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.execute = async function(dish, startFrom) {
|
Recipe.prototype.execute = async function(dish, startFrom = 0, forkState = {}) {
|
||||||
startFrom = startFrom || 0;
|
let op, input, output,
|
||||||
let op, input, output, numJumps = 0, numRegisters = 0;
|
numJumps = 0,
|
||||||
|
numRegisters = forkState.numRegisters || 0;
|
||||||
|
|
||||||
log.debug(`[*] Executing recipe of ${this.opList.length} operations, starting at ${startFrom}`);
|
log.debug(`[*] Executing recipe of ${this.opList.length} operations, starting at ${startFrom}`);
|
||||||
|
|
||||||
for (let i = startFrom; i < this.opList.length; i++) {
|
for (let i = startFrom; i < this.opList.length; i++) {
|
||||||
@ -171,7 +174,8 @@ Recipe.prototype.execute = async function(dish, startFrom) {
|
|||||||
"dish": dish,
|
"dish": dish,
|
||||||
"opList": this.opList,
|
"opList": this.opList,
|
||||||
"numJumps": numJumps,
|
"numJumps": numJumps,
|
||||||
"numRegisters": numRegisters
|
"numRegisters": numRegisters,
|
||||||
|
"forkOffset": forkState.forkOffset || 0
|
||||||
};
|
};
|
||||||
|
|
||||||
state = await op.run(state);
|
state = await op.run(state);
|
||||||
@ -256,4 +260,5 @@ Recipe.prototype.generateHighlightList = function() {
|
|||||||
return highlights;
|
return highlights;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default Recipe;
|
export default Recipe;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user