* Compute the minimum cursor across a set of consumers and count how many * consumers are at that cursor. * @param {Set} consumers - Set of objects with a `cursor` property * @param {number} fallback - Cursor to return when set is empty * @returns {{ minCursor: number, minCursorConsumers: number
(consumers, fallback)
| 77 | * @returns {{ minCursor: number, minCursorConsumers: number }} |
| 78 | */ |
| 79 | function getMinCursor(consumers, fallback) { |
| 80 | let minCursor = fallback; |
| 81 | let minCursorConsumers = 0; |
| 82 | for (const consumer of consumers) { |
| 83 | if (consumer.cursor < minCursor) { |
| 84 | minCursor = consumer.cursor; |
| 85 | minCursorConsumers = 1; |
| 86 | } else if (consumer.cursor === minCursor) { |
| 87 | minCursorConsumers++; |
| 88 | } |
| 89 | } |
| 90 | return { __proto__: null, minCursor, minCursorConsumers }; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Convert a chunk (string or Uint8Array) to Uint8Array. |
no outgoing calls
no test coverage detected