Commit 98965e0b authored by Jason Madden's avatar Jason Madden

implement libuv timer. test__socket.py passes.

parent 772e8be8
......@@ -311,6 +311,8 @@ class TimerMixin(object):
def __init__(self, loop, after=0.0, repeat=0.0, ref=True, priority=None):
if repeat < 0.0:
raise ValueError("repeat must be positive or zero: %r" % repeat)
self._after = after
self._repeat = repeat
super(TimerMixin, self).__init__(loop, ref=ref, priority=priority, args=(after, repeat))
def start(self, callback, *args, **kw):
......
......@@ -166,6 +166,7 @@ int uv_loop_alive(const uv_loop_t *loop);
int uv_loop_close(uv_loop_t* loop);
int uv_run(uv_loop_t *, uv_run_mode mode);
int uv_backend_fd(const uv_loop_t* loop);
void uv_update_time(const uv_loop_t* loop);
uint64_t uv_now(const uv_loop_t* loop);
void uv_stop(uv_loop_t *);
void uv_walk(uv_loop_t *loop, uv_walk_cb walk_cb, void *arg);
......
......@@ -113,3 +113,29 @@ class async(_base.AsyncMixin, watcher):
@property
def pending(self):
return None
class timer(_base.TimerMixin, watcher):
def _update_now(self):
self.loop.update()
_again = False
def _watcher_ffi_init(self, args):
self._watcher_init(self.loop._ptr, self._watcher)
self._after, self._repeat = args
def _watcher_ffi_start(self):
if self._again:
libuv.uv_timer_again(self._watcher)
else:
self._watcher_start(self._watcher, self._watcher_callback,
int(self._after * 1000),
int(self._repeat * 1000))
def again(self, callback, *args, **kw):
self._again = True
try:
self.start(callback, *args, **kw)
finally:
del self._again
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment