摘自:http.lua

local co_yield = coroutine.yield
local co_create = coroutine.create
local co_status = coroutine.status
local co_resume = coroutine.resume
local select = select -- Reimplemented coroutine.wrap, returning "nil, err" if the coroutine cannot
-- be resumed. This protects user code from inifite loops when doing things like
-- repeat
-- local chunk, err = res.body_reader()
-- if chunk then -- <-- This could be a string msg in the core wrap function.
-- ...
-- end
-- until not chunk
local co_wrap = function(func)
local co = co_create(func)
if not co then
return nil, "could not create coroutine"
else
return function(...)
if co_status(co) == "suspended" then
return select(2, co_resume(co, ...))
else
return nil, "can't resume a " .. co_status(co) .. " coroutine"
end
end
end
end

  

最新文章

  1. sublime_text_2 ubuntu下无法输入中文 解决方法
  2. ThreadPoolExecutor-线程池开发的使用
  3. iptables详细说明
  4. Gmail 账号找回办法
  5. poj 2240 Arbitrage
  6. JQuery快速入门
  7. 学会使用Chromium中的LOG
  8. IDEA中如何添加Scala插件。 我使用的IDEA版本是14
  9. Fedora 11中用MinGW编译Windows的Qt4程序(在Linux系统下编译Windows的程序)
  10. HTTP协议下保证登录密码不被获取更健壮方式
  11. mysql-python模块编译问题解决
  12. python脚本工具-2 去除扩展名后提取目录下所有文件名并保存
  13. Cmake 脚本对预处理器的宏定义
  14. scanf和gets的区别
  15. 《Java从入门到放弃》JavaSE入门篇:面向对象语法一(入门版)
  16. 2、C#基础 - Visual Studio 的版本选择和下载
  17. R语言︱SNA-社会关系网络 R语言实现专题(基础篇)(一)
  18. 企业IT管理员IE11升级指南【9】—— IE10与IE11的功能对比
  19. 《剑指offer》二叉搜索树的后序遍历序列
  20. 拯救者Y720-gtx1050-window10-配置tensorflow-gpu环境

热门文章

  1. Android 获取SD路径,存储空间大小的方法
  2. 【转】RO段、RW段和ZI段 --Image$$??$$Limit 含义(zz)
  3. HDU5909Tree Cutting
  4. 在centos7下用http搭建配置svn服务
  5. LinkedList(JDK1.8)源码分析
  6. cf 990G - GCD Counting
  7. win32-api: 让 static 控件中的水平横行,垂直居中。
  8. 第二十二节,TensorFlow中的图片分类模型库slim的使用、数据集处理
  9. cmd代码:查端口占用,查进程号,杀进程
  10. POJ 3678 Katu Puzzle (2-SAT)