commit
This commit is contained in:
commit
8a24549cdb
21 changed files with 3478 additions and 0 deletions
48
StartingPoint/lib/yakindu/rx.py
Normal file
48
StartingPoint/lib/yakindu/rx.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
"""Implementation for Observer and Observables used for out events.
|
||||
Generated by itemis CREATE code generator.
|
||||
"""
|
||||
|
||||
|
||||
class Observer():
|
||||
"""Observer implementation.
|
||||
"""
|
||||
|
||||
def next(self, value=None):
|
||||
"""Abstract next method, which must be implemented."""
|
||||
raise NotImplementedError('user must define next() to use this base class')
|
||||
|
||||
|
||||
class Observable():
|
||||
"""Observable implementation.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.observers = []
|
||||
|
||||
def next(self, value=None):
|
||||
"""Calls next function from every observer.
|
||||
"""
|
||||
for observer in self.observers:
|
||||
if observer is not None:
|
||||
if value is None:
|
||||
observer.next()
|
||||
else:
|
||||
observer.next(value)
|
||||
|
||||
def subscribe(self, observer):
|
||||
"""Subscribe on specified observer.
|
||||
"""
|
||||
if observer is not None:
|
||||
self.observers.append(observer)
|
||||
return True
|
||||
return False
|
||||
|
||||
def unsubscribe(self, observer):
|
||||
"""Unsubscribe from specified observer.
|
||||
"""
|
||||
if observer is None:
|
||||
return False
|
||||
if observer in self.observers:
|
||||
self.observers.remove(observer)
|
||||
return True
|
||||
return False
|
||||
Loading…
Add table
Add a link
Reference in a new issue