3 from __future__ import absolute_import, print_function
10 from .config import actor_class
12 class TimedCallBackActor(actor_class):
13 """Send messages to other actors on a schedule.
15 Other actors can call the schedule() method to schedule delivery of a
16 message at a later time. This actor runs the necessary event loop for
19 def __init__(self, max_sleep=1):
20 super(TimedCallBackActor, self).__init__()
21 self._proxy = self.actor_ref.proxy()
23 self.max_sleep = max_sleep
25 def schedule(self, delivery_time, receiver, *args, **kwargs):
28 heapq.heappush(self.messages, (delivery_time, receiver, args, kwargs))
33 til_next = self.messages[0][0] - time.time()
35 t, receiver, args, kwargs = heapq.heappop(self.messages)
37 receiver(*args, **kwargs)
38 except pykka.ActorDeadError:
41 time.sleep(min(til_next, self.max_sleep))