async-timer 1.1.3__tar.gz → 1.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: async-timer
3
- Version: 1.1.3
3
+ Version: 1.1.5
4
4
  Summary: The missing Python async timer.
5
5
  License: MIT
6
6
  Keywords: async,timer
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "async-timer"
3
- version = "v1.1.3"
3
+ version = "v1.1.5"
4
4
  description = "The missing Python async timer."
5
5
  authors = ["Ilya O. <vrghost@gmail.com>"]
6
6
  license = "MIT"
@@ -1,3 +1,4 @@
1
+ import asyncio
1
2
  import unittest.mock
2
3
 
3
4
  import async_timer
@@ -13,8 +14,23 @@ class MockPacemaker(async_timer.pacemaker.TimerPacemaker):
13
14
  async def _try_wait(self, delay: float):
14
15
  if self._cancel_evt.is_set():
15
16
  raise StopAsyncIteration()
17
+
18
+ await self._sleep_until_next_loop_iter()
16
19
  await self.sleep(delay)
17
20
 
21
+ async def _sleep_until_next_loop_iter(self):
22
+ """Awaiting this function will release on the next async loop iteration"""
23
+ fut = asyncio.Future()
24
+ asyncio.get_event_loop().call_soon(lambda: fut.set_result(42))
25
+ await fut
26
+
27
+ @classmethod
28
+ def fromPacemaker(cls, original: async_timer.pacemaker.TimerPacemaker):
29
+ """Create MockPacemaker from the non-mock original."""
30
+ out = cls(delay=original.delay)
31
+ out.stop_on(original._cancel_futs)
32
+ return out
33
+
18
34
 
19
35
  class MockTimer(async_timer.Timer):
20
36
  """Test-friendly mock timer class.
@@ -27,4 +43,4 @@ class MockTimer(async_timer.Timer):
27
43
 
28
44
  def __init__(self, *args, **kwargs):
29
45
  super().__init__(*args, **kwargs)
30
- self.pacemaker = MockPacemaker(self.pacemaker.delay)
46
+ self.pacemaker = MockPacemaker.fromPacemaker(self.pacemaker)
File without changes