promisify some Tile creation

This commit is contained in:
HF 2022-06-27 12:31:41 +02:00
parent 4a88523eab
commit ae927972ae

View File

@ -358,15 +358,15 @@ export async function createZoomedTile(
const startTime = Date.now(); const startTime = Date.now();
const na = []; const na = [];
for (let dy = 0; dy < TILE_ZOOM_LEVEL; dy += 1) {
for (let dx = 0; dx < TILE_ZOOM_LEVEL; dx += 1) { const prom = async (dx, dy) => {
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
const chunkfile = `${canvasTileFolder}/${z + 1}/${x * TILE_ZOOM_LEVEL + dx}/${y * TILE_ZOOM_LEVEL + dy}.png`; const chunkfile = `${canvasTileFolder}/${z + 1}/${x * TILE_ZOOM_LEVEL + dx}/${y * TILE_ZOOM_LEVEL + dy}.png`;
try {
if (!fs.existsSync(chunkfile)) { if (!fs.existsSync(chunkfile)) {
na.push([dx, dy]); na.push([dx, dy]);
continue; return;
} }
try {
const chunk = await sharp(chunkfile).removeAlpha().raw().toBuffer(); const chunk = await sharp(chunkfile).removeAlpha().raw().toBuffer();
addShrunkenSubtileToTile( addShrunkenSubtileToTile(
TILE_ZOOM_LEVEL, TILE_ZOOM_LEVEL,
@ -375,13 +375,21 @@ export async function createZoomedTile(
tileRGBBuffer, tileRGBBuffer,
); );
} catch (error) { } catch (error) {
na.push([dx, dy]);
console.error( console.error(
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
`Tiling: Error on createZoomedTile on chunk ${chunkfile}: ${error.message}`, `Tiling: Error on createZoomedTile on chunk ${chunkfile}: ${error.message}`,
); );
} }
};
const promises = [];
for (let dy = 0; dy < TILE_ZOOM_LEVEL; dy += 1) {
for (let dx = 0; dx < TILE_ZOOM_LEVEL; dx += 1) {
promises.push(prom(dx, dy));
} }
} }
await Promise.all(promises);
if (na.length !== TILE_ZOOM_LEVEL * TILE_ZOOM_LEVEL) { if (na.length !== TILE_ZOOM_LEVEL * TILE_ZOOM_LEVEL) {
na.forEach((element) => { na.forEach((element) => {