*
* We'll build an updated {@link GreenWorld} then return it.
*/
Next update(GreenThreadState g) {
GreenWorld d = this.with(g);
Outcome y = g.n.yield;
if (y==null) {
// no yield. rotate to next thread and keep going
return d.withNewCur().asNext(null);
}
if (y.getNormal() instanceof ThreadTask) {
// a task that needs to update/access the state
ThreadTask task = (ThreadTask)y.getNormal();
Result r = task.eval(d);
d = r.w;
if (r.suspend) // yield the value, then come back to the current thread later
return d.asNext(r.value);