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

rokucommunity / roku-debug / #2015

pending completion
#2015

push

web-flow
Merge 4961675eb into f30a7deaa

1876 of 2742 branches covered (68.42%)

Branch coverage included in aggregate %.

1876 of 1876 new or added lines in 41 files covered. (100.0%)

3422 of 4578 relevant lines covered (74.75%)

27.42 hits per line

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

93.94
/src/managers/ActionQueue.ts
1
import type { Deferred } from '../util';
2
import { defer } from '../util';
1✔
3

4
/**
5
 * A runner that will keep retrying an action until it succeeds, while also queueing up future actions.
6
 * Will run until all pending actions are complete.
7
 */
8
export class ActionQueue {
1✔
9

10
    private queueItems: Array<{
211✔
11
        action: () => boolean | Promise<boolean>;
12
        deferred: Deferred<any>;
13
        maxTries: number;
14
        tryCount: number;
15
    }> = [];
16

17
    /**
18
     * Run an action in the queue.
19
     * @param action return true or Promise<true> to mark the action as finished
20
     */
21
    public async run(action: () => boolean | Promise<boolean>, maxTries: number = undefined) {
364✔
22
        const queueItem = {
366✔
23
            action: action,
24
            deferred: defer(),
25
            maxTries: maxTries,
26
            tryCount: 0
27
        };
28
        this.queueItems.push(queueItem);
366✔
29
        await this._runActions();
366✔
30
        return queueItem.deferred.promise;
366✔
31
    }
32

33
    private isRunning = false;
211✔
34

35
    private async _runActions() {
36
        if (this.isRunning) {
366!
37
            return;
×
38
        }
39
        this.isRunning = true;
366✔
40
        while (this.queueItems.length > 0) {
366✔
41
            const queueItem = this.queueItems[0];
368✔
42
            try {
368✔
43
                queueItem.tryCount++;
368✔
44
                const isFinished = await Promise.resolve(
368✔
45
                    queueItem.action()
46
                );
47

48
                if (isFinished) {
368✔
49
                    this.queueItems.shift();
365✔
50
                    queueItem.deferred.resolve();
365✔
51
                } else if (typeof queueItem.maxTries === 'number' && queueItem.tryCount >= queueItem.maxTries) {
3✔
52
                    throw new Error(`Exceeded the ${queueItem.maxTries} maximum tries for this ActionQueue action`);
1✔
53
                }
54
            } catch (error) {
55
                this.queueItems.shift();
1✔
56
                queueItem.deferred.reject(error);
1✔
57
            }
58
        }
59
        this.isRunning = false;
366✔
60
    }
61
}
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