dbrattli / aioreactive

Async/await reactive tools for Python 3.10+
MIT License
361 stars 25 forks source link

My first AsyncObservable #19

Closed lthiery closed 6 years ago

lthiery commented 6 years ago

First off, thanks you putting this library together. I've been playing around with it and it's been real slick so far.

In light of that, I think I'm not understanding something. I'm trying to create an Observable and I'm wondering if I'm missing something. Here's what I'm doing right now:

class MyFirstObservable(AsyncObservable):
    def __init__(self, delay):
        self.observers = []

    async def __asubscribe__(self, observer):
        self.observers += [observer]

Now, when Observers subscribe, I will add them to my list. But it feels like maintaining a list of who is subscribed should be built in? When I have events to pass out, I will iterate through my observers and give them events to check out, but I'm just wondering what the intent was in not aggregating observers by default?

lthiery commented 6 years ago

Oh I see I had a fundamental misunderstanding! Each AsyncObserver is awaiting it's own response with asubscribe.

I was thinking that my AsyncObservable would need to track its Observers and push data out to them one by one. Instead it should broadcast out and I should use operations/filters to do "routing" if necessary.