Skip to content

Commit

Permalink
Add microtasks to render loop to lessen thread-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Dec 5, 2023
1 parent 6efd773 commit c0c03d0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ async function render(bbox: BBOX, options: Options = {}) {
for (const feature of features) {
drawn++;
progress(`Drawing (${drawn} / ${features.length} elements)`);
await new Promise<void>((resolve) => resolve());

const name = feature.properties?.name;
switch (feature.geometry.type) {
Expand Down Expand Up @@ -438,6 +439,7 @@ async function render(bbox: BBOX, options: Options = {}) {
const features = grouped.get(group);
if (!features) continue;
for (let feature of features) {
await new Promise<void>((resolve) => resolve());
const name = feature.properties?.name;
if (!(feature.geometry.type === "LineString" && name)) continue;
if (labeledNames.has(name) || name.length > MAX_NAME_LENGTH) continue;
Expand Down

0 comments on commit c0c03d0

Please sign in to comment.