Trying to hunt down the recipe i need but can't find it anywhere.
I have code that looks like this.
const Listeners = listen("data:join"); /* observable of people who want data */
const DataStream = stream("data"); /* observable of data */
How can i build a pipeline that:
- For each
personthat joins my listeners stream i subscribe them to the data stream. - Each person that fires a
data:leaveevent unsubscribes from the stream - DataStream's long list of pipe operators under the hood only fire once NOT once for every person who joins.
EDIT: What is the equivilent to this in a memory safe way:
Listeners.subscribe((personListening) => {
DataStream.subscribe((data) => personListening.send(data))
// And until fromEvent(personListening, "data:leave") fires.
})
/* OR */
DataStream.subscribe((data) => {
Listeners.subscribe((person) => {
person.send(data);
})
})