diff options
| author | ruki <[email protected]> | 2019-12-11 00:47:14 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-12-10 22:43:27 +0800 |
| commit | bffe4246267d83833234ec0a3819dd5c060687c2 (patch) | |
| tree | 98db4cd2a5c04b2b75ec6dbfb5e11e5d15bb6211 | |
| parent | b6dd6f29f65cab54cfbec2ec234c05abd8ab46bd (diff) | |
improve os.sleep to support scheduler
| -rw-r--r-- | tests/modules/scheduler/test.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 14 |
2 files changed, 14 insertions, 2 deletions
diff --git a/tests/modules/scheduler/test.lua b/tests/modules/scheduler/test.lua index 3e5cb83b1..cf87d2588 100644 --- a/tests/modules/scheduler/test.lua +++ b/tests/modules/scheduler/test.lua @@ -18,7 +18,7 @@ function test_sleep(t) local count = 0 local task = function (a) local dt = os.mclock() - scheduler.sleep(500) + os.sleep(500) dt = os.mclock() - dt t:require(dt > 100 and dt < 1000) count = count + 1 diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 90c5b3e04..cdcd0a029 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -25,6 +25,7 @@ local utils = require("base/utils") local xmake = require("base/xmake") local option = require("base/option") local semver = require("base/semver") +local scheduler = require("base/scheduler") local sandbox = require("sandbox/sandbox") local vformat = require("sandbox/modules/vformat") @@ -41,7 +42,6 @@ sandbox_os.args = os.args sandbox_os.argv = os.argv sandbox_os.argw = os.argw sandbox_os.mtime = os.mtime -sandbox_os.sleep = os.sleep sandbox_os.raise = os.raise sandbox_os.fscase = os.fscase sandbox_os.isroot = os.isroot @@ -481,6 +481,18 @@ function sandbox_os.readlink(symlink) return result end +-- sleep (support in coroutine) +function sandbox_os.sleep(ms) + if scheduler:co_running() then + local ok, errors = scheduler:sleep(ms) + if not ok then + raise(errors) + end + else + os.sleep(ms) + end +end + -- get xmake version function sandbox_os.xmakever() |
