MCPcopy Index your code
hub / github.com/nodejs/node / ShareImpl

Class ShareImpl

lib/internal/streams/iter/share.js:68–392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66// =============================================================================
67
68class ShareImpl {
69 #source;
70 #options;
71 #buffer = new RingBuffer();
72 #bufferStart = 0;
73 #consumers = new SafeSet();
74 #sourceIterator = null;
75 #sourceExhausted = false;
76 #sourceError = null;
77 #cancelled = false;
78 #pulling = false;
79 #pullWaiters = [];
80 #cachedMinCursor = 0;
81 #cachedMinCursorConsumers = 0;
82
83 constructor(source, options) {
84 this.#source = source;
85 this.#options = options;
86 }
87
88 get consumerCount() {
89 return this.#consumers.size;
90 }
91
92 get bufferSize() {
93 return this.#buffer.length;
94 }
95
96 pull(...args) {
97 const { transforms, options } = parsePullArgs(args);
98 const rawConsumer = this.#createRawConsumer();
99
100 if (transforms.length > 0) {
101 if (options) {
102 return pullWithTransforms(rawConsumer, ...transforms, options);
103 }
104 return pullWithTransforms(rawConsumer, ...transforms);
105 }
106 return rawConsumer;
107 }
108
109 #createRawConsumer() {
110 const state = {
111 __proto__: null,
112 cursor: this.#bufferStart,
113 resolve: null,
114 reject: null,
115 detached: false,
116 pendingNext: PromiseResolve(),
117 };
118
119 this.#consumers.add(state);
120 if (this.#consumers.size === 1) {
121 this.#cachedMinCursor = state.cursor;
122 this.#cachedMinCursorConsumers = 1;
123 } else if (state.cursor === this.#cachedMinCursor) {
124 this.#cachedMinCursorConsumers++;
125 } else {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…