• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visgl / loaders.gl / 24139120841

08 Apr 2026 01:53PM UTC coverage: 65.319% (+30.2%) from 35.137%
24139120841

push

github

web-flow
chore: Replace puppeteer with playwright (#3350)

14216 of 18890 branches covered (75.26%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

3248 existing lines in 369 files now uncovered.

73509 of 115413 relevant lines covered (63.69%)

5763.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.22
/modules/worker-utils/src/lib/async-queue/async-queue.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
2✔
3
// Copyright (c) vis.gl contributors
2✔
4

2✔
5
// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license
2✔
6
// http://2ality.com/2016/10/asynchronous-iteration.html
1✔
7

1✔
8
/**
1✔
9
 * Async Queue
1✔
10
 * - AsyncIterable: An async iterator can be
1✔
11
 * - Values can be pushed onto the queue
1✔
12
 * @example
1✔
13
 *   const asyncQueue = new AsyncQueue();
1✔
14
 *   setTimeout(() => asyncQueue.enqueue('tick'), 1000);
1✔
15
 *   setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);
1✔
16
 *   for await (const value of asyncQueue) {
1✔
17
 *     console.log(value); // tick
1✔
18
 *   }
1✔
19
 */
1✔
20
export default class AsyncQueue<T> {
1!
UNCOV
21
  private _values: any[];
✔
22
  private _settlers: any[];
2✔
23
  private _closed: boolean;
1✔
24

1✔
25
  constructor() {
1✔
26
    this._values = []; // enqueues > dequeues
2!
27
    this._settlers = []; // dequeues > enqueues
2✔
28
    this._closed = false;
2✔
29
  }
2✔
30

2✔
31
  /** Return an async iterator for this queue */
2✔
32
  [Symbol.asyncIterator](): AsyncIterator<T> {
2!
33
    return this;
2✔
34
  }
2✔
35

2✔
36
  /** Push a new value - the async iterator will yield a promise resolved to this value */
2✔
37
  push(value: T): void {
1✔
38
    return this.enqueue(value);
2✔
39
  }
2✔
40

1✔
41
  /**
1✔
42
   * Push a new value - the async iterator will yield a promise resolved to this value
1✔
43
   * Add an error - the async iterator will yield a promise rejected with this value
1✔
44
   */
1✔
45
  enqueue(value: T | Error): void {
1✔
46
    if (this._closed) {
4!
47
      throw new Error('Closed');
✔
48
    }
5✔
49

5✔
50
    if (this._settlers.length > 0) {
5✔
51
      if (this._values.length > 0) {
2!
52
        throw new Error('Illegal internal state');
2✔
53
      }
1✔
54
      const settler = this._settlers.shift();
1✔
55
      if (value instanceof Error) {
5!
56
        settler.reject(value);
1!
UNCOV
57
      } else {
×
58
        settler.resolve({value});
1✔
59
      }
1✔
60
    } else {
1✔
61
      this._values.push(value);
2✔
62
    }
2✔
63
  }
2✔
64

2✔
65
  /** Indicate that we not waiting for more values - The async iterator will be done */
2✔
66
  close(): void {
1✔
67
    while (this._settlers.length > 0) {
1!
68
      const settler = this._settlers.shift();
×
69
      settler.resolve({done: true});
×
70
    }
×
71
    this._closed = true;
1✔
72
  }
1✔
73

1✔
74
  // ITERATOR IMPLEMENTATION
1✔
75

1✔
76
  /** @returns a Promise for an IteratorResult */
1✔
77
  next(): Promise<IteratorResult<T, any>> {
1✔
78
    // If values in queue, yield the first value
5✔
79
    if (this._values.length > 0) {
5✔
80
      const value = this._values.shift();
2✔
81
      if (value instanceof Error) {
2✔
82
        return Promise.reject(value);
1✔
83
      }
1✔
84
      return Promise.resolve({done: false, value});
1✔
85
    }
1✔
86

3✔
87
    // If queue is closed, the iterator is done
3✔
88
    if (this._closed) {
5✔
89
      if (this._settlers.length > 0) {
1!
90
        throw new Error('Illegal internal state');
×
91
      }
×
92
      return Promise.resolve({done: true, value: undefined});
1✔
93
    }
1✔
94

2✔
95
    // Yield a promise that waits for new values to be enqueued
2✔
96
    return new Promise((resolve, reject) => {
2✔
97
      this._settlers.push({resolve, reject});
2✔
98
    });
2✔
99
  }
2✔
100
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc