summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-06 22:43:57 +0800
committerruki <[email protected]>2020-02-07 22:45:57 +0800
commit36ee7b8a95969aa4bfbf1d354da13dc3ba6da81d (patch)
treefb3cda1c23829fd1054af3c17f2fbd8e5acb0d85
parent7bda7f45e60afb5515d325fd098e1d4aab4c939b (diff)
fix scheduler timer/raise
-rw-r--r--xmake/core/base/scheduler.lua14
-rw-r--r--xmake/core/base/timer.lua6
-rw-r--r--xmake/core/sandbox/modules/import/core/base/timer.lua22
3 files changed, 15 insertions, 27 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index a6ad21264..b7161dd74 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -406,8 +406,9 @@ function scheduler:co_sleep(ms)
self:_timer():post(function (cancel)
if running:is_suspended() then
self:_co_tasks_suspended():remove(running)
- self:co_resume(running)
+ return self:co_resume(running)
end
+ return true
end, ms)
-- save the suspended coroutine
@@ -611,8 +612,9 @@ function scheduler:poller_wait(obj, events, timeout)
if not cancel and running:is_suspended() then
running:waitobj_set(nil)
self:_co_tasks_suspended():remove(running)
- self:co_resume(running, 0)
+ return self:co_resume(running, 0)
end
+ return true
end, timeout)
end
running:_timer_task_set(timer_task)
@@ -686,8 +688,9 @@ function scheduler:poller_waitproc(obj, timeout)
pollerdata.co_waiting = nil
running:waitobj_set(nil)
self:_co_tasks_suspended():remove(running)
- self:co_resume(running, 0)
+ return self:co_resume(running, 0)
end
+ return true
end, timeout)
end
running:_timer_task_set(timer_task)
@@ -807,7 +810,10 @@ function scheduler:runloop()
end
-- spank the timer and trigger all timeout tasks
- self:_timer():next()
+ ok, errors = self:_timer():next()
+ if not ok then
+ break
+ end
end
-- mark the loop as stopped first
diff --git a/xmake/core/base/timer.lua b/xmake/core/base/timer.lua
index 96a876bcb..78e1026cd 100644
--- a/xmake/core/base/timer.lua
+++ b/xmake/core/base/timer.lua
@@ -86,7 +86,10 @@ function timer:next()
end
-- run timer task
if task.func then
- task.func(task.cancel)
+ local ok, errors = task.func(task.cancel)
+ if not ok then
+ return false, errors
+ end
triggered = true
end
end
@@ -95,6 +98,7 @@ function timer:next()
break
end
end
+ return true
end
-- kill all timer tasks
diff --git a/xmake/core/sandbox/modules/import/core/base/timer.lua b/xmake/core/sandbox/modules/import/core/base/timer.lua
deleted file mode 100644
index 8f41644f7..000000000
--- a/xmake/core/sandbox/modules/import/core/base/timer.lua
+++ /dev/null
@@ -1,22 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-2020, TBOOX Open Source Group.
---
--- @author ruki
--- @file timer.lua
---
-
--- return module
-return require("base/timer")