最近想到一个项目应该用lua协程的地方
复习了下协程:
local t = os.clock()
local i = 0
local j = 10
co = coroutine.create(function()
while i < 100 do
curtime = os.clock()
if curtime - t > 4 then
t = curtime
i = i + 1
print(t,i)
end
if j == 10 then
coroutine.yield()
end
end
end)
coroutine.resume(co)
co1 = coroutine.create(function()
local k = 0
local t1 = os.clock()
while k < 10 do
curtime = os.clock()
if curtime - t > 1 then
k = k + 1
t1 = curtime
print("curtime", k, t1)
end
end
j = 10
coroutine.yield()
end)
coroutine.resume(co1)
问题是尾毛没有同时执行呢