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

aarong / feedme-client / 8991000982

07 May 2024 07:12PM UTC coverage: 0.0% (-99.0%) from 99.04%
8991000982

push

github

aarong
Remove legacy source code and tests; drop in new draft code

0 of 582 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 1154 new or added lines in 13 files covered. (0.0%)

0 of 1154 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/taskqueue.js
1
import _sortedLastIndexBy from "lodash/sortedLastIndexBy";
2
import macrotask from "./macrotask";
3

4
/**
5
 * Queue that invokes functions asynchronously in priority order. Ties are
6
 * resolved using insertion order, unlike heap-based priority queues.
7
 *
8
 * When multiple items are rapidly inserted into the queue, only one macrotask
9
 * is deferred up front. Another macrotask is deferred once the first one runs.
10
 * If you defer all macrotasks on insertion, then a promise settled in one
11
 * macrotask will not necessarily run before the next queue macrotasks (in
12
 * Node < v12 and polyfilled promise environments).
13
 *
14
 * @constructor
15
 */
NEW
16
const TaskQueue = function TaskQueue() {
×
17
  /**
18
   * Prioritized list of invocations to make.
19
   * Each element is: {priority, fn, args}
20
   *
21
   * @memberof TaskQueue
22
   * @instance
23
   * @type {Array}
24
   */
NEW
25
  this._queue = [];
×
26

27
  /**
28
   * True only if a macrotask has already been deferred.
29
   * @memberof TaskQueue
30
   * @instance
31
   * @type {boolean}
32
   */
NEW
33
  this._deferred = false;
×
34

35
  /**
36
   * Bound prototype._execute() function - don't re-bind constantly
37
   * @memberof TaskQueue
38
   * @instance
39
   * @type {Function}
40
   */
NEW
41
  this._boundExecute = this._execute.bind(this);
×
42
};
43

44
/**
45
 * Adds an invocation to the queue.
46
 * @memberof TaskQueue
47
 * @instance
48
 * @param {number} priority
49
 * @param {Function} fn
50
 * @param  {...*} args
51
 */
NEW
52
TaskQueue.prototype.add = function add(priority, fn, ...args) {
×
53
  // Binary search
NEW
54
  const insertIdx = _sortedLastIndexBy(
×
55
    this._queue,
56
    { priority },
NEW
57
    (queueItem) => queueItem.priority,
×
58
  );
NEW
59
  this._queue.splice(insertIdx, 0, { priority, fn, args });
×
60

61
  // Defer macrotask if there isn't one already
NEW
62
  if (!this._deferred) {
×
NEW
63
    this._deferred = true;
×
NEW
64
    macrotask(this._boundExecute);
×
65
  }
66
};
67

68
/**
69
 * Invokes a function in the queue and schedules the next.
70
 * Tasks can return truthy to run the next task synchronously (if there is one).
71
 *
72
 * Try/catch the task. If it throws, then schedule another deferral (if needed)
73
 * and re-throw the error. The library presumably does not throw, so an error
74
 * means that there was an invocation on the application.
75
 * @memberof TaskQueue
76
 * @instance
77
 */
NEW
78
TaskQueue.prototype._execute = function _execute() {
×
79
  // Run a queue item
80
  let runAnother;
81
  let err;
NEW
82
  do {
×
NEW
83
    const item = this._queue.shift();
×
NEW
84
    try {
×
NEW
85
      runAnother = !!item.fn(...item.args);
×
86
    } catch (e) {
NEW
87
      err = e;
×
NEW
88
      runAnother = false;
×
89
    }
90
  } while (runAnother && this._queue.length > 0);
×
91

92
  // Defer another?
NEW
93
  if (this._queue.length > 0) {
×
NEW
94
    macrotask(this._boundExecute);
×
95
  } else {
NEW
96
    this._deferred = false;
×
97
  }
98

99
  // Throw error?
NEW
100
  if (err) {
×
NEW
101
    throw err;
×
102
  }
103
};
104

105
// Exports
106

107
export default TaskQueue;
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