mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-10 15:02:06 -05:00
Merge pull request #1648 from mzgoddard/stop-all-next-tick
Stop all next tick
This commit is contained in:
commit
14d2820460
3 changed files with 13 additions and 4 deletions
|
@ -1844,8 +1844,12 @@ class Runtime extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.targets = newTargets;
|
this.targets = newTargets;
|
||||||
// Dispose all threads.
|
// Dispose of the active thread.
|
||||||
this.threads.forEach(thread => this._stopThread(thread));
|
if (this.sequencer.activeThread !== null) {
|
||||||
|
this._stopThread(this.sequencer.activeThread);
|
||||||
|
}
|
||||||
|
// Remove all remaining threads from executing in the next tick.
|
||||||
|
this.threads = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -51,6 +51,8 @@ class Sequencer {
|
||||||
* @type {!Runtime}
|
* @type {!Runtime}
|
||||||
*/
|
*/
|
||||||
this.runtime = runtime;
|
this.runtime = runtime;
|
||||||
|
|
||||||
|
this.activeThread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,8 +99,9 @@ class Sequencer {
|
||||||
numActiveThreads = 0;
|
numActiveThreads = 0;
|
||||||
let stoppedThread = false;
|
let stoppedThread = false;
|
||||||
// Attempt to run each thread one time.
|
// Attempt to run each thread one time.
|
||||||
for (let i = 0; i < this.runtime.threads.length; i++) {
|
const threads = this.runtime.threads;
|
||||||
const activeThread = this.runtime.threads[i];
|
for (let i = 0; i < threads.length; i++) {
|
||||||
|
const activeThread = this.activeThread = threads[i];
|
||||||
// Check if the thread is done so it is not executed.
|
// Check if the thread is done so it is not executed.
|
||||||
if (activeThread.stack.length === 0 ||
|
if (activeThread.stack.length === 0 ||
|
||||||
activeThread.status === Thread.STATUS_DONE) {
|
activeThread.status === Thread.STATUS_DONE) {
|
||||||
|
@ -165,6 +168,8 @@ class Sequencer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.activeThread = null;
|
||||||
|
|
||||||
return doneThreads;
|
return doneThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
test/fixtures/execute/control-stop-all-leaks.sb2
vendored
Normal file
BIN
test/fixtures/execute/control-stop-all-leaks.sb2
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue