@speckle/objectloader2
Version:
This is an updated objectloader for the Speckle viewer written in typescript
37 lines (33 loc) • 936 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.
}
}
}
disposeAsync(): Promise<void> {
this.
return Promise.resolve()
}
}