@speckle/objectloader2
Version:
This is an updated objectloader for the Speckle viewer written in typescript
36 lines (32 loc) • 893 B
text/typescript
import Queue from './queue.js'
export default class AsyncGeneratorQueue<T> implements Queue<T> {
add(value: T): void {
if (this.
// If there's a pending consumer, resolve immediately
const resolve = this.
resolve(value)
} else {
// Otherwise, add to the buffer
this.
}
}
async *consume(): AsyncGenerator<T> {
while (
!this.
this.
this.
) {
if (this.
yield this.
} else {
yield await new Promise<T>((resolve) => this.
}
}
}
dispose(): void {
this.
}
}