diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2018-02-01 17:59:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-01 17:59:32 (GMT) |
commit | 3d4dbd8f019c0bbac99fc9248077044ff1039ca3 (patch) | |
tree | 4a01df373f516fc9b92afeb80f8531d0fcdef647 /Lib | |
parent | 83ab995871ffd504ac229bdbf5b9e9ffc1032815 (diff) | |
download | cpython-3d4dbd8f019c0bbac99fc9248077044ff1039ca3.zip cpython-3d4dbd8f019c0bbac99fc9248077044ff1039ca3.tar.gz cpython-3d4dbd8f019c0bbac99fc9248077044ff1039ca3.tar.bz2 |
Implement TimerHandle.when() (#5473)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asyncio/events.py | 8 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_events.py | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index bdefcf6..fcca5d4 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -156,6 +156,14 @@ class TimerHandle(Handle): self._loop._timer_handle_cancelled(self) super().cancel() + def when(self): + """Return a scheduled callback time. + + The time is an absolute timestamp, using the same time + reference as loop.time(). + """ + return self._when + class AbstractServer: """Abstract server returned by create_server().""" diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index f54802c..f599597 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -2679,6 +2679,12 @@ class TimerTests(unittest.TestCase): mock.Mock()) self.assertEqual(hash(h), hash(when)) + def test_when(self): + when = time.monotonic() + h = asyncio.TimerHandle(when, lambda: False, (), + mock.Mock()) + self.assertEqual(when, h.when()) + def test_timer(self): def callback(*args): return args |