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 () {