I’m pretty sure the answer to this question is gonna be “no”, but checking in case I’ve missed something obvious…
Question: Is there a way to check if the current Routine has yielded or not?
I.e. is there a method/primite with auto-reset-on-yield with behavior like:
"something".yield;
// more code
this.hasYielded; // -> true
// more code without yield
this.hasYielded; // -> false
If you have full control over “more code” above, this is of course trivial to implement with a local flag, but in general it would be useful in a case like
retval = fn.value(); // function passed by user that may yield or not
if (this.hasYielded.not, { "default stuff".yield });
One can of course implement some protocol so that retval
additionally carries a flag whether the function fn
has yielded or not, but this requires explicit cooperation from fn
to set/return that flag, which means most existing functions cannot simply be plugged in fn
's place.
So, is there a Routine-level way to check if it has yielded or not?
If you’re curious on the background for this issue, it’s related to bug report 4642, essentially the behavior of repeating patterns (like Pn
) when the sub-pattern they embed is empty (not nil
, but actually empty i.e. p{}
).