Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
include: update uv_timer doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Aug 15, 2012
1 parent 2c3e8b6 commit 90a75b0
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions include/uv.h
Expand Up @@ -1093,8 +1093,7 @@ UV_EXTERN int uv_async_send(uv_async_t* async);
/*
* uv_timer_t is a subclass of uv_handle_t.
*
* Wraps libev's ev_timer watcher. Used to get woken up at a specified time
* in the future.
* Used to get woken up at a specified time in the future.
*/
struct uv_timer_s {
UV_HANDLE_FIELDS
Expand All @@ -1103,8 +1102,22 @@ struct uv_timer_s {

UV_EXTERN int uv_timer_init(uv_loop_t*, uv_timer_t* timer);

UV_EXTERN int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb,
int64_t timeout, int64_t repeat);
/*
* Start the timer. `timeout` and `repeat` are in milliseconds.
*
* If timeout is zero, the callback fires on the next tick of the event loop.

This comment has been minimized.

Copy link
@shigeki

shigeki Aug 15, 2012

This is not true when repeat is non-zero because new timeout is the repeat value as https://github.com/joyent/libuv/blob/v0.8/src/unix/timer.c#L89

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Aug 16, 2012

Author Contributor

Not sure I'm following... the code you link to is in uv_timer_again().

This comment has been minimized.

Copy link
@shigeki

shigeki Aug 16, 2012

IIRC, for example case of uv_timer_start(timer, timer_cb, 0, 1) , uv_timer_again() is invoked in uv__run_timers() before timer_cb(). So timeout is changed as uv_timer_start(timer, timer_cb, 1, 1) at the next repeat.

This comment has been minimized.

Copy link
@shigeki

shigeki Aug 16, 2012

@bnoordhuis I had found this at the test of setImmediate recursion. Please refer nodejs/node-v0.x-archive#3872

*
* If repeat is non-zero, the callback fires first after timeout milliseconds
* and then repeatedly after repeat milliseconds.
*
* timeout and repeat are signed integers but that will change in a future
* version of libuv. Don't pass in negative values, you'll get a nasty surprise
* when that change becomes effective.
*/
UV_EXTERN int uv_timer_start(uv_timer_t* timer,
uv_timer_cb cb,
int64_t timeout,
int64_t repeat);

UV_EXTERN int uv_timer_stop(uv_timer_t* timer);

Expand All @@ -1116,10 +1129,10 @@ UV_EXTERN int uv_timer_stop(uv_timer_t* timer);
UV_EXTERN int uv_timer_again(uv_timer_t* timer);

/*
* Set the repeat value. Note that if the repeat value is set from a timer
* callback it does not immediately take effect. If the timer was non-repeating
* before, it will have been stopped. If it was repeating, then the old repeat
* value will have been used to schedule the next timeout.
* Set the repeat value in milliseconds. Note that if the repeat value is set
* from a timer callback it does not immediately take effect. If the timer was
* non-repeating before, it will have been stopped. If it was repeating, then
* the old repeat value will have been used to schedule the next timeout.
*/
UV_EXTERN void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat);

Expand Down

0 comments on commit 90a75b0

Please sign in to comment.