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

Class SyncShareImpl

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

Source from the content-addressed store, hash-verified

396// =============================================================================
397
398class SyncShareImpl {
399 #source;
400 #options;
401 #buffer = new RingBuffer();
402 #bufferStart = 0;
403 #consumers = new SafeSet();
404 #sourceIterator = null;
405 #sourceExhausted = false;
406 #sourceError = null;
407 #cancelled = false;
408 #cachedMinCursor = 0;
409 #cachedMinCursorConsumers = 0;
410
411 constructor(source, options) {
412 this.#source = source;
413 this.#options = options;
414 }
415
416 get consumerCount() {
417 return this.#consumers.size;
418 }
419
420 get bufferSize() {
421 return this.#buffer.length;
422 }
423
424 pull(...transforms) {
425 const rawConsumer = this.#createRawConsumer();
426
427 if (transforms.length > 0) {
428 return pullSyncWithTransforms(rawConsumer, ...transforms);
429 }
430 return rawConsumer;
431 }
432
433 #createRawConsumer() {
434 const state = {
435 __proto__: null,
436 cursor: this.#bufferStart,
437 detached: false,
438 };
439
440 this.#consumers.add(state);
441 if (this.#consumers.size === 1) {
442 this.#cachedMinCursor = state.cursor;
443 this.#cachedMinCursorConsumers = 1;
444 } else if (state.cursor === this.#cachedMinCursor) {
445 this.#cachedMinCursorConsumers++;
446 } else {
447 this.#recomputeMinCursor();
448 }
449 const self = this;
450
451 return {
452 __proto__: null,
453 [SymbolIterator]() {
454 return {
455 __proto__: null,

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…