From e9fee73b62132d7fd5554da6a8237c0adf04d75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 28 Sep 2022 19:09:44 +0800 Subject: test delay refresh node cache #1595 --- script/vm/node.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'script/vm') diff --git a/script/vm/node.lua b/script/vm/node.lua index 49207b13..9b10fa9d 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -3,6 +3,7 @@ local files = require 'files' local vm = require 'vm.vm' local ws = require 'workspace.workspace' local guide = require 'parser.guide' +local timer = require 'timer' ---@type table vm.nodeCache = {} @@ -475,10 +476,22 @@ function vm.createNode(a, b) return node end +---@type timer? +local delayTimer files.watch(function (ev, uri) if ev == 'version' then if ws.isReady(uri) then - vm.clearNodeCache() + if PREVIEW then + if delayTimer then + delayTimer:restart() + end + delayTimer = timer.wait(1, function () + delayTimer = nil + vm.clearNodeCache() + end) + else + vm.clearNodeCache() + end end end end) -- cgit v1.2.3