lua 协程的理解
参考链接:
http://www.cnblogs.com/zrtqsk/p/4374360.html
对例子的自我理解:
-- 协程的理解 -- co 是协程的内容,类似函数内容, 通过yield 将中止函数的操作, -- 但重新resume后,将继续执行co未执行到内容 function foo(a) print("foo", a) return coroutine.yield(2 * a) end co = coroutine.create(function ( a, b ) print("co-body", a, b) local r = foo(a + 1) print("co-body", r) local r, s = coroutine.yield(a + b, a - b) print("co-body", r, s) return b, "end" end) -- resume首次传递参数 yield 返回true 与 yield的参数 local c, d = coroutine.resume(co, 1, 10) print("main:", c, d) print("main", coroutine.resume(co, "r")) print("main", coroutine.resume(co, "x", "y")) print("main", coroutine.resume(co, "x", "y")) -- 执行结果 -- co-body 1 10 -- foo 2 -- main true 4 -- co-body r -- main true 11 -9 -- co-body x y -- main true 10 end -- main false cannot resume dead coroutine
lua协程是协作式多任务,用于异步通信的机制,参考链接:
http://blog.csdn.net/sharemyfree/article/details/47442115
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?