加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

lua协程

发布时间:2020-12-14 22:07:42 所属栏目:大数据 来源:网络整理
导读:最近想到一个项目应该用lua协程的地方 复习了下协程: local t = os.clock()local i = 0local j = 10co = 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 cor

最近想到一个项目应该用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)
问题是尾毛没有同时执行呢

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读