mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-25 09:01:07 -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.
|
// We've run before; check if the wait is still going on.
|
||||||
var waiting = false;
|
var instance = this;
|
||||||
for (var i = 0; i < util.stackFrame.triggeredThreads.length; i++) {
|
var waiting = util.stackFrame.triggeredThreads.some(function(thread) {
|
||||||
var thread = util.stackFrame.triggeredThreads[i];
|
return instance.runtime.isActiveThread(thread);
|
||||||
var activeThreads = this.runtime.threads;
|
});
|
||||||
if (activeThreads.indexOf(thread) > -1) { // @todo: A cleaner way?
|
|
||||||
waiting = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
util.yieldFrame();
|
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.
|
* Toggle a script.
|
||||||
* @param {!string} topBlockId ID of block that starts the script.
|
* @param {!string} topBlockId ID of block that starts the script.
|
||||||
|
|
Loading…
Reference in a new issue