Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/core/classes/prism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export default class Prism {
if (!this.config.manual) {
this.waitFor.push(documentReady());

this.ready = allSettled(this.waitFor);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this workaround anymore: we set the initial value of ready on line 35.

this.ready
.then(() => {
this.highlightAll();
Expand Down
14 changes: 12 additions & 2 deletions src/util/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,19 @@ export function nextTick () {
});
}

// In addition to waiting for all promises to settle, handle post-hoc additions/removals.
export async function allSettled<T> (promises: Promise<T>[]): Promise<(T | null)[]> {
const outcomes = await Promise.allSettled(promises);
return outcomes.map(o => (o.status === 'fulfilled' ? o.value : null));
return Promise.allSettled(promises).then(outcomes => {
if (promises.length > 0 && promises.length !== outcomes.length) {
// The list of promises changed. Return a new Promise.
// The original promise won't resolve until the new one does.
return allSettled(promises);
}

// The list of promises either empty or stayed the same.
// Return results immediately.
return outcomes.map(o => (o.status === 'fulfilled' ? o.value : null));
});
}

export class Deferred<T> extends Promise<T> {
Expand Down