failure to yieldto is not the same thing as not calling yieldto in the first place
$done to success. The fact that $done1
has a final value of failure shows that the attempt to yield back
to p1 failed, so how did control end up in p1 again?
variable done
proc p0 {} {
yield
variable done0
after 0 [list [namespace which c1]]
vwait [namespace current]::done0
}
proc p1 {} {
variable done0
yield
yieldto try "yieldto [list [info coroutine]]" on error {} "
::set [list [namespace current]]::done1 failure
::set [list [namespace current]]::done0 failure
"
set done0 success
}
coroutine c0 p0
coroutine c1 p1
after 1 [list [namespace which c0]]
vwait [namespace current]::done0
puts [list status $done0 $done1]
output:
status success failure
If the script doesn't attempt the inner yieldto, and just sets the variables instead, the result is different:
variable done
proc p0 {} {
yield
variable done0
after 0 [list [namespace which c1]]
vwait [namespace current]::done0
}
proc p1 {} {
variable done0
yield
yieldto try "
::set [list [namespace current]]::done1 failure
::set [list [namespace current]]::done0 failure
"
set done0 success
}
coroutine c0 p0
coroutine c1 p1
after 1 [list [namespace which c0]]
vwait [namespace current]::done0
puts [list status $done0 $done1]
output:
status failure failure
So apparently in the first script the failure to yield back to c1 affects some internal state and changes the outcome.
Duplicate of [f9800d52bd61f240].
Test case added in [5cfdd6ee7b7f2099].