js: Make retire() smarter

This commit is contained in:
Thomas Weber committed 2020-08-23 11:14:49 -05:00
1 parent 411dea526e
commit 9555b68381
1 file changed
+9 -1
+9 -1
View File
@@ -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 () {