File tree Expand file tree Collapse file tree 3 files changed +36
-11
lines changed Expand file tree Collapse file tree 3 files changed +36
-11
lines changed Original file line number Diff line number Diff line change 2222local m = {}
2323
2424m ._eventList = {}
25+ m ._watchings = {}
2526
2627function m .watch (path )
27- local id = fw .add (path )
28+ if m ._watchings [path ] then
29+ m ._watchings [path ].count = m ._watchings [path ].count + 1
30+ else
31+ m ._watchings [path ] = {
32+ count = 1 ,
33+ id = fw .add (path ),
34+ }
35+ log .debug (' fw.add' , path )
36+ end
37+ local removed
2838 return function ()
29- fw .remove (id )
39+ if removed then
40+ return
41+ end
42+ removed = true
43+ m ._watchings [path ].count = m ._watchings [path ].count - 1
44+ if m ._watchings [path ].count == 0 then
45+ fw .remove (m ._watchings [path ].id )
46+ m ._watchings [path ] = nil
47+ log .debug (' fw.remove' , path )
48+ end
3049 end
3150end
3251
Original file line number Diff line number Diff line change 1+ local gc = require ' gc'
2+
13--- @alias scope.type ' "override"' | ' "folder"' | ' "fallback"'
24
35--- @class scope
46--- @field type scope.type
57--- @field uri ? uri
68--- @field _links table<uri , boolean>
79--- @field _data table<string , any>
10+ --- @field _gc gc
811local mt = {}
912mt .__index = mt
1013
@@ -97,13 +100,23 @@ function mt:getName()
97100 return self .uri or (' <' .. self .type .. ' >' )
98101end
99102
103+ function mt :gc (obj )
104+ self ._gc :add (obj )
105+ end
106+
107+ function mt :flushGC ()
108+ self ._gc :remove ()
109+ self ._gc = gc ()
110+ end
111+
100112--- @param scopeType scope.type
101113--- @return scope
102114local function createScope (scopeType )
103115 local scope = setmetatable ({
104116 type = scopeType ,
105117 _links = {},
106118 _data = {},
119+ _gc = gc (),
107120 }, mt )
108121
109122 return scope
Original file line number Diff line number Diff line change @@ -267,14 +267,7 @@ function m.awaitPreload(scp)
267267 await .setID (' preload:' .. scp :getName ())
268268 await .sleep (0.1 )
269269
270- local watchers = scp :get ' watchers'
271- if watchers then
272- for _ , dispose in ipairs (watchers ) do
273- dispose ()
274- end
275- end
276- watchers = {}
277- scp :set (' watchers' , watchers )
270+ scp :flushGC ()
278271
279272 local ld <close> = loading .create (scp )
280273 scp :set (' loading' , ld )
@@ -301,7 +294,7 @@ function m.awaitPreload(scp)
301294 scp :get (' cachedUris' )[furi .encode (path )] = true
302295 ld :loadFile (furi .encode (path ), libMatcher .uri )
303296 end )
304- watchers [ # watchers + 1 ] = fw .watch (furi .decode (libMatcher .uri ))
297+ scp : gc ( fw .watch (furi .decode (libMatcher .uri ) ))
305298 end
306299
307300 -- must wait for other scopes to add library
You can’t perform that action at this time.
0 commit comments