Skip to content

Commit

Permalink
Fix up hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
rizerphe committed Feb 5, 2024
1 parent 04c2796 commit dd8b114
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ class ExhaustableConsumable<T> {
}

let next_items: { item: T }[] = [];
let next_item_promise: Promise<void> = Promise.resolve();
let next_item_promise: Promise<void> | null = Promise.resolve();
const add_resolver = () => {
next_item_promise = new Promise<void>((resolve) => {
this.consumers.push((item) => {
if (item == null) {
if (item === null) {
// I have no clue why this is necessary
// but oh well, as long as it works
next_item_promise = null;
return resolve();
}
next_items.push(item);
Expand All @@ -65,7 +68,7 @@ class ExhaustableConsumable<T> {
});
};
add_resolver();
while (!this.exhausted) {
while (!this.exhausted && next_item_promise !== null) {
await next_item_promise;
while (next_items.length > 0) {
const next_item = next_items.shift();
Expand Down

0 comments on commit dd8b114

Please sign in to comment.