예제 #1
0
 def to_result(self):
     """
     Returns the current state of this signal as a result (i.e. a success or failure)
     """
     try:
         return result.Success(self.now)
     except Exception as e:
         return result.Failure(e)
예제 #2
0
 def update(self, new_value, propagator = Propagator.instance()):
     """
     Updates the current value of this signal to the new value and propagates
     the change through the data-flow graph
     """
     
     if new_value != self.__current:
         self.__current = new_value
         # Propagate the update
         propagator.propagate(self, result.Success(self.__current))
예제 #3
0
 def __recalculate(self):
     # Link ourself to our dependencies as we go
     tracking.begin(lambda dep: dep.link_child(self))
     # If an error occurs during the calculation, we want to store it
     r = None
     try:
         r = result.Success(self.__calc())
     except Exception as e:
         r = result.Failure(e)
     finally:
         tracking.end()
     return r
예제 #4
0
 def __lshift__(self, value):
     """
     Emits the given value at the next opportunity
     """
     self.__to_emit = result.Success(value)
     return self
예제 #5
0
 def emit(self, value, propagator=Propagator.instance()):
     """
     Propagates the given value through the data-flow graph
     """
     propagator.propagate(self, result.Success(value))