Skip to content

Commit 1d878d2

Browse files
committed
unix,win: add uv_timer_get_timeout()
Refs: nodejs/node-report#73
1 parent 67f4d1c commit 1d878d2

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

docs/src/timer.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@ API
7373
7474
Get the timer repeat value.
7575
76+
.. c:function:: uint64_t uv_timer_get_timeout(const uv_timer_t* handle)
77+
78+
Get the timer timeout value.
79+
7680
.. seealso:: The :c:type:`uv_handle_t` API functions also apply.

include/uv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ UV_EXTERN int uv_timer_stop(uv_timer_t* handle);
787787
UV_EXTERN int uv_timer_again(uv_timer_t* handle);
788788
UV_EXTERN void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat);
789789
UV_EXTERN uint64_t uv_timer_get_repeat(const uv_timer_t* handle);
790+
UV_EXTERN uint64_t uv_timer_get_timeout(const uv_timer_t* handle);
790791

791792

792793
/*

src/unix/timer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ uint64_t uv_timer_get_repeat(const uv_timer_t* handle) {
126126
}
127127

128128

129+
uint64_t uv_timer_get_timeout(const uv_timer_t* handle) {
130+
return handle->timeout;
131+
}
132+
133+
129134
int uv__next_timeout(const uv_loop_t* loop) {
130135
const struct heap_node* heap_node;
131136
const uv_timer_t* handle;

src/win/timer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ uint64_t uv_timer_get_repeat(const uv_timer_t* handle) {
153153
}
154154

155155

156+
uint64_t uv_timer_get_timeout(const uv_timer_t* handle) {
157+
assert(handle->type == UV_TIMER);
158+
return handle->due;
159+
}
160+
161+
156162
DWORD uv__next_timeout(const uv_loop_t* loop) {
157163
uv_timer_t* timer;
158164
int64_t delta;

test/test-timer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ TEST_IMPL(timer_init) {
161161

162162
ASSERT(0 == uv_timer_init(uv_default_loop(), &handle));
163163
ASSERT(0 == uv_timer_get_repeat(&handle));
164+
ASSERT(0 == uv_timer_get_timeout(&handle));
164165
ASSERT(0 == uv_is_active((uv_handle_t*) &handle));
165166

166167
MAKE_VALGRIND_HAPPY();
@@ -232,6 +233,9 @@ TEST_IMPL(timer_huge_timeout) {
232233
ASSERT(0 == uv_timer_start(&tiny_timer, tiny_timer_cb, 1, 0));
233234
ASSERT(0 == uv_timer_start(&huge_timer1, tiny_timer_cb, 0xffffffffffffLL, 0));
234235
ASSERT(0 == uv_timer_start(&huge_timer2, tiny_timer_cb, (uint64_t) -1, 0));
236+
ASSERT(1 == uv_timer_get_timeout(&tiny_timer));
237+
ASSERT(0xffffffffffffLL == uv_timer_get_timeout(&huge_timer1));
238+
ASSERT((uint64_t) -1 == uv_timer_get_timeout(&huge_timer2));
235239
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
236240
MAKE_VALGRIND_HAPPY();
237241
return 0;

0 commit comments

Comments
 (0)