File tree 3 files changed +36
-11
lines changed
3 files changed +36
-11
lines changed Original file line number Diff line number Diff line change 22
22
local m = {}
23
23
24
24
m ._eventList = {}
25
+ m ._watchings = {}
25
26
26
27
function 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
28
38
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
30
49
end
31
50
end
32
51
Original file line number Diff line number Diff line change
1
+ local gc = require ' gc'
2
+
1
3
--- @alias scope.type ' "override"' | ' "folder"' | ' "fallback"'
2
4
3
5
--- @class scope
4
6
--- @field type scope.type
5
7
--- @field uri ? uri
6
8
--- @field _links table<uri , boolean>
7
9
--- @field _data table<string , any>
10
+ --- @field _gc gc
8
11
local mt = {}
9
12
mt .__index = mt
10
13
@@ -97,13 +100,23 @@ function mt:getName()
97
100
return self .uri or (' <' .. self .type .. ' >' )
98
101
end
99
102
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
+
100
112
--- @param scopeType scope.type
101
113
--- @return scope
102
114
local function createScope (scopeType )
103
115
local scope = setmetatable ({
104
116
type = scopeType ,
105
117
_links = {},
106
118
_data = {},
119
+ _gc = gc (),
107
120
}, mt )
108
121
109
122
return scope
Original file line number Diff line number Diff line change @@ -267,14 +267,7 @@ function m.awaitPreload(scp)
267
267
await .setID (' preload:' .. scp :getName ())
268
268
await .sleep (0.1 )
269
269
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 ()
278
271
279
272
local ld <close> = loading .create (scp )
280
273
scp :set (' loading' , ld )
@@ -301,7 +294,7 @@ function m.awaitPreload(scp)
301
294
scp :get (' cachedUris' )[furi .encode (path )] = true
302
295
ld :loadFile (furi .encode (path ), libMatcher .uri )
303
296
end )
304
- watchers [ # watchers + 1 ] = fw .watch (furi .decode (libMatcher .uri ))
297
+ scp : gc ( fw .watch (furi .decode (libMatcher .uri ) ))
305
298
end
306
299
307
300
-- must wait for other scopes to add library
You can’t perform that action at this time.
0 commit comments