# expected: done
# Cooperative scheduler demo using coroutines (generator style)
# coroutine eagerly collects all yields; invoking the coroutine name pops values

proc counter {n max} {
    while {$n < $max} {
        yield $n
        incr n
    }
    yield done
}

coroutine gen1 counter 0 3

# gen1 yields: 0 1 2 done
set out {}
for {set i 0} {$i < 4} {incr i} {
    lappend out [gen1]
}

# last val is "done"
lindex $out 3
