码迷,mamicode.com
首页 > Web开发 > 详细

http.lua里的装饰器

时间:2017-11-22 20:10:41      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:fit   font   body   tin   this   could   zed   --   turn   

 

摘自: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

  

http.lua里的装饰器

标签:fit   font   body   tin   this   could   zed   --   turn   

原文地址:http://www.cnblogs.com/standby/p/7880565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!