Skip to content

Commit

Permalink
refactor Multicast
Browse files Browse the repository at this point in the history
  • Loading branch information
martypdx committed Mar 5, 2024
1 parent 3a21ed0 commit 2acd761
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/channels/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,24 @@ export function multicast(iterator) {
}

export class Multicast {
consumers = [];
#consumers = [];

constructor(subject) {
this.subject = subject;
this.#start();
}

async #start() {
for await(let value of this.subject) {
for(let consumer of this.consumers) {
for(let consumer of this.#consumers) {
consumer(value);
}
}
}

subscriber(transform, options) {
const [iterator, dispatch] = subject(transform, options);
this.consumers.push(dispatch);
this.#consumers.push(dispatch);
return iterator;
}
}

0 comments on commit 2acd761

Please sign in to comment.