Skip to content

Commit afb0b06

Browse files
call_later should always return TimerHandle
1 parent 74f4c96 commit afb0b06

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

tests/test_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,12 @@ def test_loop_call_later_handle_when_after_fired(self):
938938
self.loop.run_until_complete(fut)
939939
self.assertEqual(handle.when(), when)
940940

941+
def test_loop_call_later_0_returns_timer_handle(self):
942+
cb = lambda: False # NoQA
943+
handle = self.loop.call_later(0, cb)
944+
handle.when() # undesired behavior: handle is a Handle instead of TimerHandle
945+
handle.cancel()
946+
941947

942948
class TestBaseAIO(_TestBase, AIOTestCase):
943949
pass

uvloop/loop.pyx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,10 +1326,7 @@ cdef class Loop:
13261326
when = <uint64_t>round(delay * 1000)
13271327
if not args:
13281328
args = None
1329-
if when == 0:
1330-
return self._call_soon(callback, args, context)
1331-
else:
1332-
return self._call_later(when, callback, args, context)
1329+
return self._call_later(when, callback, args, context)
13331330

13341331
def call_at(self, when, callback, *args, context=None):
13351332
"""Like call_later(), but uses an absolute time.

0 commit comments

Comments
 (0)