mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-10 15:02:06 -05:00
Add isActiveThread
and simplify broadcast-and-wait accordingly
This commit is contained in:
parent
64b82f4dc2
commit
40c90bbcc7
2 changed files with 13 additions and 8 deletions
|
@ -71,14 +71,10 @@ Scratch3EventBlocks.prototype.broadcastAndWait = function (args, util) {
|
|||
}
|
||||
}
|
||||
// We've run before; check if the wait is still going on.
|
||||
var waiting = false;
|
||||
for (var i = 0; i < util.stackFrame.triggeredThreads.length; i++) {
|
||||
var thread = util.stackFrame.triggeredThreads[i];
|
||||
var activeThreads = this.runtime.threads;
|
||||
if (activeThreads.indexOf(thread) > -1) { // @todo: A cleaner way?
|
||||
waiting = true;
|
||||
}
|
||||
}
|
||||
var instance = this;
|
||||
var waiting = util.stackFrame.triggeredThreads.some(function(thread) {
|
||||
return instance.runtime.isActiveThread(thread);
|
||||
});
|
||||
if (waiting) {
|
||||
util.yieldFrame();
|
||||
}
|
||||
|
|
|
@ -211,6 +211,15 @@ Runtime.prototype._removeThread = function (thread) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Return whether a thread is currently active/running.
|
||||
* @param {?Thread} thread Thread object to check.
|
||||
* @return {Boolean} True if the thread is active/running.
|
||||
*/
|
||||
Runtime.prototype.isActiveThread = function (thread) {
|
||||
return this.threads.indexOf(thread) > -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle a script.
|
||||
* @param {!string} topBlockId ID of block that starts the script.
|
||||
|
|
Loading…
Reference in a new issue