MCPcopy Create free account
hub / github.com/nodejs/node / getMinCursor

Function getMinCursor

lib/internal/streams/iter/utils.js:79–91  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

77 * @returns {{ minCursor: number, minCursorConsumers: number }}
78 */
79function 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.

Callers 3

#recomputeMinCursorMethod · 0.85
#recomputeMinCursorMethod · 0.85
#recomputeMinCursorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected