local consumer = coroutine.create(function(i)
while true do
i = i - 1
print('consumer: ' .. i)
coroutine.yield(i)
end
end)
local producer = coroutine.create(function()
while true do
i = i or 0
i = i + 1
print('producer: ' .. i)
status, value = coroutine.resume(consumer, i)
i = value
end
end)
coroutine.resume(producer)
但这是完全错误的,正确的印刷应该是这样的: 0 1 0 1 01
答案 0 :(得分:0)
在使用者中将coroutine.yield(i)替换为i = coroutine.yield(i)。 @EgorSkriptunoff感谢您的帮助