MCPcopy Create free account
hub / github.com/Effect-TS/effect / publishAll

Method publishAll

packages/effect/src/PubSub.ts:1554–1583  ·  view source on GitHub ↗
(elements: Iterable<A>)

Source from the content-addressed store, hash-verified

1552 }
1553
1554 publishAll(elements: Iterable<A>): Array<A> {
1555 if (this.subscriberCount === 0) {
1556 if (this.replayBuffer) {
1557 this.replayBuffer.offerAll(elements)
1558 }
1559 return []
1560 }
1561 const chunk = Arr.fromIterable(elements)
1562 const n = chunk.length
1563 const size = this.publisherIndex - this.subscribersIndex
1564 const available = this.capacity - size
1565 const forPubSub = Math.min(n, available)
1566 if (forPubSub === 0) {
1567 return chunk
1568 }
1569 let iteratorIndex = 0
1570 const publishAllIndex = this.publisherIndex + forPubSub
1571 while (this.publisherIndex !== publishAllIndex) {
1572 const a = chunk[iteratorIndex++]
1573 const index = this.publisherIndex % this.capacity
1574 this.array[index] = a
1575 const replayIndex = this.replayBuffer?.offer(a)
1576 if (replayIndex !== undefined) {
1577 this.replayIndices[index] = replayIndex
1578 }
1579 this.subscribers[index] = this.subscriberCount
1580 this.publisherIndex += 1
1581 }
1582 return chunk.slice(iteratorIndex)
1583 }
1584
1585 slide(): void {
1586 if (this.subscribersIndex !== this.publisherIndex) {

Callers

nothing calls this directly

Calls 2

offerAllMethod · 0.80
offerMethod · 0.80

Tested by

no test coverage detected