Skip to content
Snippets Groups Projects
Commit d20d2d2d authored by 最萌小汐's avatar 最萌小汐
Browse files

await.wait 也要使用延迟检查器

parent 390108b1
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ local fs = require 'bee.filesystem' ...@@ -5,7 +5,7 @@ local fs = require 'bee.filesystem'
ROOT = fs.path(rootPath) ROOT = fs.path(rootPath)
LANG = LANG or 'en-US' LANG = LANG or 'en-US'
--collectgarbage('generational', 10, 50) collectgarbage('generational', 10, 50)
--collectgarbage('incremental', 120, 120, 0) --collectgarbage('incremental', 120, 120, 0)
log = require 'log' log = require 'log'
......
...@@ -31,6 +31,7 @@ function m.create(callback, ...) ...@@ -31,6 +31,7 @@ function m.create(callback, ...)
return m.checkResult(co, coroutine.resume(co, ...)) return m.checkResult(co, coroutine.resume(co, ...))
end end
--- 对当前任务设置一个延迟检查器,当延迟前后检查器的返回值不同时,放弃此任务
function m.setDelayer(callback) function m.setDelayer(callback)
local co = coroutine.running() local co = coroutine.running()
m.coDelayer[co] = callback m.coDelayer[co] = callback
...@@ -47,8 +48,11 @@ function m.sleep(time, getVersion) ...@@ -47,8 +48,11 @@ function m.sleep(time, getVersion)
end end
local version = getVersion and getVersion() local version = getVersion and getVersion()
local co = coroutine.running() local co = coroutine.running()
local delayer = m.coDelayer[co]
local dVersion = delayer and delayer()
timer.wait(time, function () timer.wait(time, function ()
if version == (getVersion and getVersion()) then if version == (getVersion and getVersion())
and dVersion == (delayer and delayer()) then
return m.checkResult(co, coroutine.resume(co)) return m.checkResult(co, coroutine.resume(co))
else else
coroutine.close(co) coroutine.close(co)
......
...@@ -2,6 +2,7 @@ local vm = require 'vm.vm' ...@@ -2,6 +2,7 @@ local vm = require 'vm.vm'
local files = require 'files' local files = require 'files'
local ws = require 'workspace' local ws = require 'workspace'
local guide = require 'parser.guide' local guide = require 'parser.guide'
local await = require 'await'
local m = {} local m = {}
...@@ -63,6 +64,7 @@ function vm.interface.call(func, args, index) ...@@ -63,6 +64,7 @@ function vm.interface.call(func, args, index)
if not lib then if not lib then
return nil return nil
end end
await.delay()
if lib.name == 'require' and index == 1 then if lib.name == 'require' and index == 1 then
return m.require(args, index) return m.require(args, index)
end end
...@@ -72,9 +74,11 @@ function vm.interface.call(func, args, index) ...@@ -72,9 +74,11 @@ function vm.interface.call(func, args, index)
end end
function vm.interface.global(name) function vm.interface.global(name)
await.delay()
return vm.getGlobals(name) return vm.getGlobals(name)
end end
function vm.interface.link(uri) function vm.interface.link(uri)
await.delay()
return vm.getLinksTo(uri) return vm.getLinksTo(uri)
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment