Modify all serve_* modules to return a Promise (preparation for #140)

This commit is contained in:
Petr Sloup
2017-05-10 08:51:26 +02:00
parent c233d23523
commit d30027e992
6 changed files with 119 additions and 70 deletions
+16 -9
View File
@@ -15,16 +15,19 @@ module.exports = function(options, allowedFonts) {
var fontPath = options.paths.fonts;
var existingFonts = {};
fs.readdir(options.paths.fonts, function(err, files) {
files.forEach(function(file) {
fs.stat(path.join(fontPath, file), function(err, stats) {
if (!err) {
if (stats.isDirectory() &&
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))) {
existingFonts[path.basename(file)] = true;
var fontListingPromise = new Promise(function(resolve, reject) {
fs.readdir(options.paths.fonts, function(err, files) {
files.forEach(function(file) {
fs.stat(path.join(fontPath, file), function(err, stats) {
if (!err) {
if (stats.isDirectory() &&
fs.existsSync(path.join(fontPath, file, '0-255.pbf'))) {
existingFonts[path.basename(file)] = true;
}
}
}
});
});
resolve();
});
});
@@ -55,5 +58,9 @@ module.exports = function(options, allowedFonts) {
);
});
return app;
return new Promise(function(resolve, reject) {
fontListingPromise.then(function() {
resolve(app);
});
});
};