| 26 | |
| 27 | |
| 28 | class AsyncCallbackCaller: |
| 29 | |
| 30 | def __init__(self, cb=None, delay=0, args=(), kwargs={}): |
| 31 | self.caller = cb |
| 32 | self.delay = delay |
| 33 | self.args = args |
| 34 | self.kwargs = kwargs |
| 35 | self.call_count = 0 |
| 36 | |
| 37 | def trigger(self, *args, **kwargs): |
| 38 | self.call_count += 1 |
| 39 | Thread(target=self._make_call).start() |
| 40 | |
| 41 | def call_and_wait(self): |
| 42 | thread = Thread(target=self._make_call) |
| 43 | thread.start() |
| 44 | thread.join() |
| 45 | |
| 46 | def _make_call(self): |
| 47 | time.sleep(self.delay) |
| 48 | self.caller.call(*self.args, **self.kwargs) |
no outgoing calls