def add_callback(self, method): """ Attaches a mehtod that will be called when the future finishes. :param method: A callable from an actor that will be called when the future completes. The only argument for that method must be the future itself from wich you can get the result though `future.:meth:`result()``. If the future has already completed, then the callable will be called immediately. .. note:: This functionallity only works when called from an actor, specifying a method from the same actor. """ from_actor = get_current() if from_actor is not None: callback = (method, from_actor.channel, from_actor.url) with self.__condition: if self.__state is not FINISHED: self.__callbacks.append(callback) return # Invoke the callback directly # msg = TellRequest(TELL, method, [self], from_actor.url) msg = {TYPE: TELL, METHOD: method, PARAMS: [self], TO: from_actor.url} from_actor.channel.send(msg) else: raise FutureError("add_callback only works when called " + "from inside an actor")
def add_callback(self, method): """ Attaches a mehtod that will be called when the future finishes. :param method: A callable from an actor that will be called when the future completes. The only argument for that method must be the future itself from wich you can get the result though `future.:meth:`result()``. If the future has already completed, then the callable will be called immediately. .. note:: This functionallity only works when called from an actor, specifying a method from the same actor. """ from_actor = get_current() if from_actor is not None: callback = (method, from_actor.channel, from_actor.url) # with self.__condition: if self.__state is not FINISHED: self.__callbacks.append(callback) return # Invoke the callback directly # msg = TellRequest(TELL, method, [self], from_actor.url) msg = {TYPE: TELL, METHOD: method, PARAMS: ([self], {}), TO: from_actor.url} from_actor.channel.send(msg) else: raise FutureError("add_callback only works when called " + "from inside an actor")