In Sciter any function that contains yield
keyword is treated as a generator function.
Main purpose of the generator is to produce sequence of values – on each generator invocation it returns next value.
Generator returns next value when yield <expression>
is executed by the generator.
Consider this generator function:
function ordinals() { yield "first"; yield "second"; yield "third"; }
And the code that uses it:
for(var ordinal in ordinals()) stdout.println(ordinal);
Body of the loop will be executed three times as on each generator invocation next yield will emit its value.
And so you will get this output:
> first > second > third
The yield
(in generators) and await
(asynchronous tasks) are internal incarnations of the same mechanism – coroutines.