summaryrefslogtreecommitdiff
path: root/script-beta/service
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-02 11:36:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-02 11:36:45 +0800
commit33beca3671744d7d7add8310774a5b01c3392188 (patch)
tree2d2cb8f05084ce9aeacab2ba5a5b805ab9c67798 /script-beta/service
parentd34679f9d8a92ccb0f4ad98b420a9e6a0340711a (diff)
downloadlua-language-server-33beca3671744d7d7add8310774a5b01c3392188.zip
后台cpu消耗
Diffstat (limited to 'script-beta/service')
-rw-r--r--script-beta/service/service.lua11
1 files changed, 11 insertions, 0 deletions
diff --git a/script-beta/service/service.lua b/script-beta/service/service.lua
index 11cc7b19..3e912cb7 100644
--- a/script-beta/service/service.lua
+++ b/script-beta/service/service.lua
@@ -4,6 +4,7 @@ local await = require 'await'
local timer = require 'timer'
local proto = require 'proto'
local vm = require 'vm'
+local config = require 'config'
local m = {}
m.type = 'service'
@@ -133,13 +134,23 @@ function m.report()
end
function m.startTimer()
+ local clock = os.clock()
while true do
::CONTINUE::
pub.step()
if await.step() then
+ local passed = os.clock() - clock
+ local cpu = config.config.misc.backGroundCPU
+ if cpu >= 1 and cpu < 100 then
+ local sleepRate = (100 - cpu) / cpu
+ local extraSleep = math.min(passed * sleepRate, 0.1)
+ thread.sleep(extraSleep)
+ end
+ clock = os.clock()
goto CONTINUE
end
thread.sleep(0.001)
+ clock = os.clock()
timer.update()
end
end