Lua协程-测试3

时间:2023-03-09 14:35:08
Lua协程-测试3
print("Lua 协程测试3")

-- 实现消费者-生产者关系(生产一个就消费一个)
count = -- 生产总数 -- 生产者
local newProductorCo = coroutine.create( --创建协程
function()
local i =
while(i <= count)do
coroutine.yield(i) -- 挂起协程
i = i +
end
end) -- 消费者
for i=,count do
local status,value = coroutine.resume(newProductorCo)
print(status,value)
end 运行结果:
Lua 协程测试3
true
true
true
true
true
true
true
true
true
true