add STOP_FOR_TARGET runtime event and respond for ask blocks

Remove questions for targets that are individually stopping and
progress the asked question if it is from a stopping target.
This commit is contained in:
Michael "Z" Goddard 2018-10-02 12:44:13 -04:00
parent 4583cb821b
commit 574749bbba
No known key found for this signature in database
GPG key ID: 762CD40DD5349872
3 changed files with 112 additions and 0 deletions
src/engine

View file

@ -377,6 +377,15 @@ class Runtime extends EventEmitter {
return 'PROJECT_STOP_ALL';
}
/**
* Event name for target being stopped by a stop for target call.
* Used by blocks that need to stop individual targets.
* @const {string}
*/
static get STOP_FOR_TARGET () {
return 'STOP_FOR_TARGET';
}
/**
* Event name for visual value report.
* @const {string}
@ -1382,6 +1391,9 @@ class Runtime extends EventEmitter {
* @param {Thread=} optThreadException Optional thread to skip.
*/
stopForTarget (target, optThreadException) {
// Emit stop event to allow blocks to clean up any state.
this.emit(Runtime.STOP_FOR_TARGET, target, optThreadException);
// Stop any threads on the target.
for (let i = 0; i < this.threads.length; i++) {
if (this.threads[i] === optThreadException) {