Revert to while-loop based execution
This commit is contained in:
parent
65aa9c9ecd
commit
dbfacece2c
@ -15,7 +15,6 @@ class ExecutionController<RS> {
|
|||||||
private _breakpoints: number[] = [];
|
private _breakpoints: number[] = [];
|
||||||
private _result: StepExecutionResult<RS> | null;
|
private _result: StepExecutionResult<RS> | null;
|
||||||
private _resolvePause: (() => void) | null = null;
|
private _resolvePause: (() => void) | null = null;
|
||||||
private _execInterval: NodeJS.Timeout | null = null;
|
|
||||||
private _isPaused: boolean = false;
|
private _isPaused: boolean = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,20 +104,21 @@ class ExecutionController<RS> {
|
|||||||
* Execute the loaded program until stopped.
|
* Execute the loaded program until stopped.
|
||||||
* @param param0.interval Interval between two execution steps
|
* @param param0.interval Interval between two execution steps
|
||||||
* @param param0.onResult Callback called with result on each execution step
|
* @param param0.onResult Callback called with result on each execution step
|
||||||
|
* @returns Promise that resolves with result of last execution step
|
||||||
*/
|
*/
|
||||||
executeAll({ interval, onResult }: ExecuteAllArgs<RS>) {
|
executeAll({ interval, onResult }: ExecuteAllArgs<RS>) {
|
||||||
// Clear paused state
|
// Clear paused state
|
||||||
this._isPaused = false;
|
this._isPaused = false;
|
||||||
|
|
||||||
// Run execution loop using an Interval
|
return new Promise(async (resolve) => {
|
||||||
this._execInterval = setInterval(() => {
|
while (true) {
|
||||||
const doBreak = this.runExecLoopIteration();
|
const doBreak = this.runExecLoopIteration();
|
||||||
onResult(this._result!);
|
onResult(this._result!);
|
||||||
if (doBreak) {
|
if (doBreak) break;
|
||||||
clearInterval(this._execInterval!);
|
await this.sleep(interval);
|
||||||
this._execInterval = null;
|
|
||||||
}
|
}
|
||||||
}, interval);
|
resolve(this._result!);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,6 +151,11 @@ class ExecutionController<RS> {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sleep for `ms` milliseconds */
|
||||||
|
private sleep(ms: number): Promise<void> {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ExecutionController;
|
export default ExecutionController;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user