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

visgl / loaders.gl / 24153816851

08 Apr 2026 07:17PM UTC coverage: 53.247% (-12.1%) from 65.319%
24153816851

push

github

web-flow
chore: Move from tape to vitest (#3351)

8651 of 17291 branches covered (50.03%)

Branch coverage included in aggregate %.

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

2031 existing lines in 296 files now uncovered.

17563 of 31940 relevant lines covered (54.99%)

5279.54 hits per line

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

61.4
/modules/schema-utils/src/lib/utils/async-queue.ts
1
// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license
2
// http://2ality.com/2016/10/asynchronous-iteration.html
3

4
class ArrayQueue<T> extends Array<T> {
5
  enqueue(value: T) {
6
    // Add at the end
7
    return this.push(value);
135✔
8
  }
9
  dequeue(): T {
10
    // Remove first element
11
    return this.shift() as T;
60✔
12
  }
13
}
14

15
export default class AsyncQueue<T> {
16
  private _values: ArrayQueue<T | Error>;
17
  private _settlers: ArrayQueue<{resolve: (value: any) => void; reject: (reason?: any) => void}>;
18
  private _closed: boolean;
19

20
  constructor() {
21
    // enqueues > dequeues
22
    this._values = new ArrayQueue<T>();
40✔
23
    // dequeues > enqueues
24
    this._settlers = new ArrayQueue<{
40✔
25
      resolve: (value: any) => void;
26
      reject: (reason?: any) => void;
27
    }>();
28
    this._closed = false;
40✔
29
  }
30

31
  close(): void {
32
    while (this._settlers.length > 0) {
40✔
UNCOV
33
      this._settlers.dequeue().resolve({done: true});
×
34
    }
35
    this._closed = true;
40✔
36
  }
37

38
  [Symbol.asyncIterator](): AsyncIterator<T> {
39
    return this;
39✔
40
  }
41

42
  enqueue(value: T | Error): void {
43
    if (this._closed) {
135!
44
      throw new Error('Closed');
×
45
    }
46

47
    if (this._settlers.length > 0) {
135✔
48
      if (this._values.length > 0) {
40!
UNCOV
49
        throw new Error('Illegal internal state');
×
50
      }
51
      const settler = this._settlers.dequeue();
40✔
52
      if (value instanceof Error) {
40!
UNCOV
53
        settler.reject(value);
×
54
      } else {
55
        settler.resolve({value});
40✔
56
      }
57
    } else {
58
      this._values.enqueue(value);
95✔
59
    }
60
  }
61

62
  /**
63
   * @returns a Promise for an IteratorResult
64
   */
65
  next(): Promise<any> {
66
    if (this._values.length > 0) {
98✔
67
      const value = this._values.dequeue();
20✔
68
      if (value instanceof Error) {
20!
69
        return Promise.reject(value);
×
70
      }
71
      return Promise.resolve({value});
20✔
72
    }
73

74
    if (this._closed) {
78✔
75
      if (this._settlers.length > 0) {
38!
76
        throw new Error('Illegal internal state');
×
77
      }
78
      return Promise.resolve({done: true});
38✔
79
    }
80
    // Wait for new values to be enqueued
81
    return new Promise((resolve, reject) => {
40✔
82
      this._settlers.enqueue({resolve, reject});
40✔
83
    });
84
  }
85
}
86

87
/**
88
 * @returns a Promise for an Array with the elements in `asyncIterable`
89
 */
90
export async function takeAsync(
91
  asyncIterable: AsyncIterable<any>,
92
  count = Infinity
×
93
): Promise<any[]> {
94
  const result: Array<any> = [];
×
95
  const iterator = asyncIterable[Symbol.asyncIterator]();
×
96
  while (result.length < count) {
×
97
    const {value, done} = await iterator.next();
×
98
    if (done) {
×
99
      break;
×
100
    }
101
    result.push(value);
×
102
  }
103
  return result;
×
104
}
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