unix: update timer if already active
uv_timer_start() no longer returns an error when the timer is already active, now it just updates the timer. Consistent with the uv-win implementation. Fixes #425.
This commit is contained in:
parent
ae9d4c2aab
commit
028fef84b8
@ -52,11 +52,12 @@ int uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) {
|
||||
}
|
||||
|
||||
|
||||
int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout,
|
||||
int64_t repeat) {
|
||||
if (uv__is_active(timer)) {
|
||||
return -1;
|
||||
}
|
||||
int uv_timer_start(uv_timer_t* timer,
|
||||
uv_timer_cb cb,
|
||||
int64_t timeout,
|
||||
int64_t repeat) {
|
||||
if (uv__is_active(timer))
|
||||
uv_timer_stop(timer);
|
||||
|
||||
timer->timer_cb = cb;
|
||||
|
||||
|
||||
@ -77,6 +77,7 @@ TEST_DECLARE (callback_stack)
|
||||
TEST_DECLARE (error_message)
|
||||
TEST_DECLARE (timer)
|
||||
TEST_DECLARE (timer_again)
|
||||
TEST_DECLARE (timer_start_twice)
|
||||
TEST_DECLARE (idle_starvation)
|
||||
TEST_DECLARE (loop_handles)
|
||||
TEST_DECLARE (get_loadavg)
|
||||
@ -266,6 +267,7 @@ TASK_LIST_START
|
||||
|
||||
TEST_ENTRY (timer)
|
||||
TEST_ENTRY (timer_again)
|
||||
TEST_ENTRY (timer_start_twice)
|
||||
|
||||
TEST_ENTRY (idle_starvation)
|
||||
|
||||
|
||||
@ -131,3 +131,22 @@ TEST_IMPL(timer) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
TEST_IMPL(timer_start_twice) {
|
||||
uv_timer_t once;
|
||||
int r;
|
||||
|
||||
r = uv_timer_init(uv_default_loop(), &once);
|
||||
ASSERT(r == 0);
|
||||
r = uv_timer_start(&once, never_cb, 86400 * 1000, 0);
|
||||
ASSERT(r == 0);
|
||||
r = uv_timer_start(&once, once_cb, 10, 0);
|
||||
ASSERT(r == 0);
|
||||
r = uv_run(uv_default_loop());
|
||||
ASSERT(r == 0);
|
||||
|
||||
ASSERT(once_cb_called == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user