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

Method publishAll

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

Source from the content-addressed store, hash-verified

1748 }
1749
1750 publishAll(elements: Iterable<A>): Array<A> {
1751 if (this.subscriberCount === 0) {
1752 if (this.replayBuffer) {
1753 this.replayBuffer.offerAll(elements)
1754 }
1755 return []
1756 }
1757 const chunk = Arr.fromIterable(elements)
1758 const n = chunk.length
1759 const size = this.publisherIndex - this.subscribersIndex
1760 const available = this.capacity - size
1761 const forPubSub = Math.min(n, available)
1762 if (forPubSub === 0) {
1763 return chunk
1764 }
1765 let iteratorIndex = 0
1766 const publishAllIndex = this.publisherIndex + forPubSub
1767 while (this.publisherIndex !== publishAllIndex) {
1768 const elem = chunk[iteratorIndex++]
1769 const index = this.publisherIndex & this.mask
1770 this.array[index] = elem
1771 const replayIndex = this.replayBuffer?.offer(elem)
1772 if (replayIndex !== undefined) {
1773 this.replayIndices[index] = replayIndex
1774 }
1775 this.subscribers[index] = this.subscriberCount
1776 this.publisherIndex += 1
1777 }
1778 return chunk.slice(iteratorIndex)
1779 }
1780
1781 slide(): void {
1782 if (this.subscribersIndex !== this.publisherIndex) {

Callers

nothing calls this directly

Calls 2

offerAllMethod · 0.80
offerMethod · 0.80

Tested by

no test coverage detected