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
在消费者中用i = coroutine.yield(i)替换coroutine.yield(i)。@EgorSkriptunoff感谢您的帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句