Skip to content

Commit f3a7580

Browse files
committed
Merge branch 'adamcarheden-cache-async'
2 parents 79ce5ff + 235bc37 commit f3a7580

File tree

6 files changed

+187
-72
lines changed

6 files changed

+187
-72
lines changed

package-lock.json

Lines changed: 69 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"make-dir": "^1.3.0",
3131
"markdownlint": "^0.8.1",
3232
"markdownlint-cli": "^0.8.1",
33-
"nw": "^0.31.4",
33+
"nw": "^0.31.5",
3434
"nw-builder": "^3.5.4",
3535
"replace-in-file": "^3.4.0",
3636
"rimraf": "^2.6.2"

src/cache/cache.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,60 +73,63 @@ cwc.Cache.prototype.prepare = async function() {
7373
/**
7474
* @param {!string|number} version
7575
*/
76-
cwc.Cache.prototype.update = function(version) {
76+
cwc.Cache.prototype.update = async function(version) {
7777
if (version && this.version <= version) {
7878
this.log_.info('No updates needed', version, '>=', this.version);
7979
return;
8080
}
8181

8282
this.log_.info('Updating Cache to version', this.version);
83-
this.database_.clear();
83+
await this.database_.clear();
8484

8585
this.log_.info('Loading external frameworks ...');
86-
this.loadFiles(cwc.framework.External);
86+
await this.loadFiles(cwc.framework.External);
8787

8888
this.log_.info('Loading internal frameworks ...');
89-
this.loadFiles(cwc.framework.Internal);
89+
await this.loadFiles(cwc.framework.Internal);
9090

9191
this.log_.info('Loading Style Sheets ...');
92-
this.loadFiles(cwc.framework.StyleSheet);
92+
await this.loadFiles(cwc.framework.StyleSheet);
9393

94-
this.database_.add('__version__', this.version);
94+
await this.database_.add('__version__', this.version);
9595
};
9696

9797

9898
/**
9999
* Loads files into cache.
100100
* @param {!Object} files
101101
*/
102-
cwc.Cache.prototype.loadFiles = function(files) {
102+
cwc.Cache.prototype.loadFiles = async function(files) {
103+
let promises = [];
103104
for (let file of Object.keys(files)) {
104105
if (goog.isString(files[file])) {
105-
cwc.utils.Resources.getUriAsText('..' + files[file]).then((content) => {
106-
this.addFile(files[file], content);
107-
});
106+
promises.push(cwc.utils.Resources.getUriAsText('..' + files[file])
107+
.then((content) => {
108+
return this.addFile(files[file], content);
109+
}));
108110
} else {
109111
for (let subFile of Object.keys(files[file])) {
110-
cwc.utils.Resources.getUriAsText('..' + files[file][subFile]).then(
111-
(content) => {
112-
this.addFile(files[file][subFile], content);
113-
});
112+
promises.push(cwc.utils.Resources.getUriAsText('..' +
113+
files[file][subFile]).then((content) => {
114+
return this.addFile(files[file][subFile], content);
115+
}));
114116
}
115117
}
116118
}
119+
await Promise.all(promises);
117120
};
118121

119122

120123
/**
121124
* @param {string!} name
122125
* @param {string!} content
123126
*/
124-
cwc.Cache.prototype.addFile = function(name, content) {
127+
cwc.Cache.prototype.addFile = async function(name, content) {
125128
if (!content) {
126129
this.log_.error('Received empty content for', name);
127130
return;
128131
}
129-
this.database_.add(name, content);
132+
await this.database_.add(name, content);
130133
};
131134

132135

src/ui/builder.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ cwc.ui.Builder.prototype.decorateUI = function() {
292292
this.events_.clear();
293293
this.loadingScreen_.hideSecondsAfterStart(3000);
294294
resolve();
295+
}).catch((error) => {
296+
this.log_.error('Failed to load cache', error);
295297
});
296298
});
297299
};

0 commit comments

Comments
 (0)