Added observables

This commit is contained in:
2023-04-15 16:17:31 +02:00
parent 8dee4d8f70
commit efc9cf9c83
11 changed files with 254 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
from typing import Callable
from cpl_reactive_extensions.observer import Observer
class Observable:
def __init__(self, callback: Callable):
self._callback = callback
self._subscriptions: list[Callable] = []
def _run_subscriptions(self):
for callback in self._subscriptions:
callback()
def subscribe(self, observer: Observer):
try:
self._callback(observer)
except Exception as e:
observer.error(e)