From 0a006dc9811e9b7008189169d2e4ce45de29b5fa Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Wed, 6 Jun 2018 09:57:53 -0400 Subject: [PATCH] add Runtime.isWaitingThread Add a Runtime Thread helper to check if a thread is in a state where it will not change at least until next frame. This includes any state where the thread is done, as that will not change either. --- src/engine/runtime.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index ab38955e..3acfe4bb 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1017,6 +1017,19 @@ class Runtime extends EventEmitter { this.threads.indexOf(thread) > -1); } + /** + * Return whether a thread is waiting for more information or done. + * @param {?Thread} thread Thread object to check. + * @return {boolean} True if the thread is waiting + */ + isWaitingThread (thread) { + return ( + thread.status === Thread.STATUS_PROMISE_WAIT || + thread.status === Thread.STATUS_YIELD_TICK || + !this.isActiveThread(thread) + ); + } + /** * Toggle a script. * @param {!string} topBlockId ID of block that starts the script.