Skip to content

Commit

Permalink
rm default timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubleSpout committed Mar 17, 2017
1 parent 653db1a commit 0b2f252
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion aries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local Aries = {
rootPath = "./tpl",
sep = "/",
isShowDetailError = true, -- must set off in production
timeout = 10, --sec
timeout = -1, --sec
ctx = {},
getInclude = function(self, includeName)
return self.readfile(string.format("%s%s%s.%s", self.rootPath, self.sep, includeName, self.fileSuffix))
Expand Down
49 changes: 28 additions & 21 deletions lib/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -406,30 +406,37 @@ tplLib.compile = function(self, code)

-- 开启一个协程来渲染模版
local func = self:exec(code, self.mainTplName, ctx)
local coroutineFunc = function()
local co = coroutine.create(func)
local start = os.time()
local ok,errMsg = coroutine.resume(co)
if not ok then
error(errMsg, 2)
end
while true do -- 判断超时渲染
if (ariesIns.timeout > 0) and (os.time() - start > ariesIns.timeout) then
error(" render tmplate is timeout ", 2)
break
elseif coroutine.status(co) == "dead" then
break
else
local ok,errMsg = coroutine.resume(co)
if not ok then
error(errMsg, 2)
if ariesIns.timeout > 0 then
local coroutineFunc = function()
local co = coroutine.create(func)
local start = os.time()
local ok,errMsg = coroutine.resume(co)
if not ok then
error(errMsg, 2)
end
while true do -- 判断超时渲染
if (ariesIns.timeout > 0) and (os.time() - start > ariesIns.timeout) then
error(" render tmplate is timeout ", 2)
break
elseif coroutine.status(co) == "dead" then
break
else
local ok,errMsg = coroutine.resume(co)
if not ok then
error(errMsg, 2)
end
end
end
end
end
local ok, err = pcall(coroutineFunc)
if not ok then
error(self.mainTplName .. " have error " .. err, 2)
local ok, err = pcall(coroutineFunc)
if not ok then
error(string.format("%s have error %s", self.mainTplName, err), 2)
end
else
local ok, err = pcall(func)
if not ok then
error(string.format("%s have error %s", self.mainTplName, err), 2)
end
end

return table.concat(result, "")
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ we can get error msg, correct to postion the error line, even it at include temp
isShowDetailError = true,

-- template render timeout, unit seconde
timeout = 10,
-- default not timeout
timeout = -1,

-- instance level object to put to template
ctx = {},
Expand Down

0 comments on commit 0b2f252

Please sign in to comment.