@@ -14,6 +14,7 @@ local pub = require 'pub'
1414--- @field _stash function[]
1515--- @field _refs uri[]
1616--- @field _cache table<uri , boolean>
17+ --- @field _sets function[]
1718--- @field _removed boolean
1819local mt = {}
1920mt .__index = mt
@@ -94,6 +95,9 @@ function mt:loadFile(uri, libraryUri)
9495 return
9596 end
9697 log .debug ((' Preload file at: %s , size = %.3f KB' ):format (uri , # content / 1024.0 ))
98+ await .wait (function (waker )
99+ self ._sets [# self ._sets + 1 ] = waker
100+ end )
97101 files .setText (uri , content , false )
98102 if not self ._cache [uri ] then
99103 files .addRef (uri )
@@ -125,6 +129,9 @@ function mt:loadFile(uri, libraryUri)
125129 return
126130 end
127131 log .debug ((' Preload dll at: %s , size = %.3f KB' ):format (uri , # content / 1024.0 ))
132+ await .wait (function (waker )
133+ self ._sets [# self ._sets + 1 ] = waker
134+ end )
128135 files .saveDll (uri , content )
129136 if not self ._cache [uri ] then
130137 files .addRef (uri )
141148
142149--- @async
143150function mt :loadAll ()
151+ local startClock = os.clock ()
152+ log .info (' Load files from disk:' , self .scp :getName ())
144153 while self .read < self .max do
145154 self :update ()
146155 local loader = table.remove (self ._stash )
@@ -151,7 +160,17 @@ function mt:loadAll()
151160 await .sleep (0.1 )
152161 end
153162 end
154- log .info (' Loaded finish.' )
163+ local loadedClock = os.clock ()
164+ log .info ((' Loaded files takes [%.3f] sec: %s' ):format (loadedClock - startClock , self .scp :getName ()))
165+ self ._bar :remove ()
166+ self ._bar = progress .create (self .scp .uri , lang .script (' WORKSPACE_LOADING' , self .scp .uri ), 0 )
167+ for i , set in ipairs (self ._sets ) do
168+ set ()
169+ self .read = i
170+ self :update ()
171+ end
172+ log .info ((' Compile files takes [%.3f] sec: %s' ):format (os.clock () - loadedClock , self .scp :getName ()))
173+ log .info (' Loaded finish:' , self .scp :getName ())
155174end
156175
157176function mt :remove ()
@@ -179,6 +198,7 @@ function m.create(scp)
179198 _bar = progress .create (scp .uri , lang .script (' WORKSPACE_LOADING' , scp .uri ), 0.5 ),
180199 _stash = {},
181200 _cache = {},
201+ _sets = {},
182202 }, mt )
183203 m ._loadings [loading ] = true
184204 return loading
0 commit comments