pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/MagicStack/uvloop/commit/62b2af9c724dd9550d81dfafe983e8b86069df41

/assets/repository-6534fbc3f5e83ac0.css" /> Add support for <timer handle>.when() · MagicStack/uvloop@62b2af9 · GitHub
Skip to content

Commit 62b2af9

Browse files
Jens Jorgensenelprans
authored andcommitted
Add support for <timer handle>.when()
1 parent 20febe0 commit 62b2af9

4 files changed

Lines changed: 19 additions & 0 deletions

File tree

tests/test_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,15 @@ async def main():
852852
self.assertEqual(OK, 5)
853853
self.assertEqual(NOT_OK, 0)
854854

855+
def test_loop_call_later_handle_when(self):
856+
cb = lambda: False # NoQA
857+
delay = 1.0
858+
loop_t = self.loop.time()
859+
handle = self.loop.call_later(delay, cb)
860+
self.assertAlmostEqual(handle.when(), loop_t + delay, places=2)
861+
handle.cancel()
862+
self.assertTrue(handle.cancelled())
863+
855864

856865
class TestBaseAIO(_TestBase, AIOTestCase):
857866
pass

uvloop/cbhandles.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ cdef class TimerHandle:
308308
def cancel(self):
309309
self._cancel()
310310

311+
def when(self):
312+
return self.timer.get_when() * 1e-3
313+
311314

312315
cdef format_callback_name(func):
313316
if hasattr(func, '__qualname__'):

uvloop/handles/timer.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ cdef class UVTimer(UVHandle):
44
object ctx
55
bint running
66
uint64_t timeout
7+
uint64_t start_t
78

89
cdef _init(self, Loop loop, method_t callback, object ctx,
910
uint64_t timeout)
1011

1112
cdef stop(self)
1213
cdef start(self)
14+
cdef get_when(self)
1315

1416
@staticmethod
1517
cdef UVTimer new(Loop loop, method_t callback, object ctx,

uvloop/handles/timer.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cdef class UVTimer(UVHandle):
2323
self.ctx = ctx
2424
self.running = 0
2525
self.timeout = timeout
26+
self.start_t = 0
2627

2728
cdef stop(self):
2829
cdef int err
@@ -47,6 +48,7 @@ cdef class UVTimer(UVHandle):
4748
if self.running == 0:
4849
# Update libuv internal time.
4950
uv.uv_update_time(self._loop.uvloop) # void
51+
self.start_t = uv.uv_now(self._loop.uvloop)
5052

5153
err = uv.uv_timer_start(<uv.uv_timer_t*>self._handle,
5254
__uvtimer_callback,
@@ -57,6 +59,9 @@ cdef class UVTimer(UVHandle):
5759
return
5860
self.running = 1
5961

62+
cdef get_when(self):
63+
return self.start_t + self.timeout
64+
6065
@staticmethod
6166
cdef UVTimer new(Loop loop, method_t callback, object ctx,
6267
uint64_t timeout):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy