美文网首页
Lua练习21-lua的协程

Lua练习21-lua的协程

作者: GameObjectLgy | 来源:发表于2020-10-16 16:01 被阅读0次
    co2 = coroutine.create(
        function()
            for i=1,10 do
                print(i)
                if i == 3 then
                    print(coroutine.status(co2))  --running
                    print(coroutine.running()) --thread:XXXXXX
                end
                coroutine.yield()
            end
        end
    )
     
    coroutine.resume(co2) --1
    coroutine.resume(co2) --2
    coroutine.resume(co2) --3
     
    print(coroutine.status(co2))   -- suspended
    print(coroutine.running())
     
    print("----------")
    

    结果:
    1
    2
    3
    running
    thread: 000002D22CB860C8 false
    suspended
    thread: 000002D22CAC9428 true


    相关文章

      网友评论

          本文标题:Lua练习21-lua的协程

          本文链接:https://www.haomeiwen.com/subject/xbwzyktx.html