From 9555b683813ee0f0a5604db75bf2e80fddfc920b Mon Sep 17 00:00:00 2001 From: Thomas Weber Date: Sun, 23 Aug 2020 11:14:49 -0500 Subject: [PATCH] js: Make retire() smarter --- src/compiler/jsgen.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/compiler/jsgen.js b/src/compiler/jsgen.js index cafde85c..58486dc5 100644 --- a/src/compiler/jsgen.js +++ b/src/compiler/jsgen.js @@ -593,7 +593,15 @@ class ScriptCompiler { } retire () { - this.source += 'retire(); yield;\n'; + // After running retire(), we need to return to the event loop. + // When in a procedure, return will only send us back to the previous procedure. + // So instead, we yield back to the event loop. + // Outside of a procedure, return will work correctly. + if (this.isProcedure) { + this.source += 'retire(); yield;\n'; + } else { + this.source += 'retire(); return;\n'; + } } yieldLoop () {