diff --git a/src/compiler/jsexecute.js b/src/compiler/jsexecute.js index 8b444317..cb0dd036 100644 --- a/src/compiler/jsexecute.js +++ b/src/compiler/jsexecute.js @@ -116,19 +116,20 @@ const waitPromise = function*(promise) { const thread = globalState.thread; let returnValue; + // enter STATUS_PROMISE_WAIT and yield + // this will stop script execution until the promise handlers reset the thread status + // because promise handlers might execute immediately, configure thread.status here + thread.status = 1; // STATUS_PROMISE_WAIT + promise .then(value => { returnValue = value; thread.status = 0; // STATUS_RUNNING - }) - .catch(error => { + }, error => { thread.status = 0; // STATUS_RUNNING globalState.log.warn('Promise rejected in compiled script:', error); }); - // enter STATUS_PROMISE_WAIT and yield - // this will stop script execution until the promise handlers reset the thread status - thread.status = 1; // STATUS_PROMISE_WAIT yield; return returnValue;