From 61e8adb25e6f37c3c9df0dd8f4fea5e23b62bacd Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 21 Apr 2016 17:06:03 +0200 Subject: eval: implement timers. vim-patch: 7.4.1578, 7.4.1831 For the moment, timers are triggered during sleep, but not in wait-for-input modes, like press-RETURN or f_getchar() --- src/nvim/event/time.c | 5 +++++ src/nvim/event/time.h | 1 + 2 files changed, 6 insertions(+) (limited to 'src/nvim/event') diff --git a/src/nvim/event/time.c b/src/nvim/event/time.c index 7bf333bcea..f68a66345f 100644 --- a/src/nvim/event/time.c +++ b/src/nvim/event/time.c @@ -17,6 +17,7 @@ void time_watcher_init(Loop *loop, TimeWatcher *watcher, void *data) watcher->uv.data = watcher; watcher->data = data; watcher->events = loop->fast_events; + watcher->blockable = false; } void time_watcher_start(TimeWatcher *watcher, time_cb cb, uint64_t timeout, @@ -50,6 +51,10 @@ static void time_watcher_cb(uv_timer_t *handle) FUNC_ATTR_NONNULL_ALL { TimeWatcher *watcher = handle->data; + if (watcher->blockable && !queue_empty(watcher->events)) { + // the timer blocked and there already is an unprocessed event waiting + return; + } CREATE_EVENT(watcher->events, time_event, 1, watcher); } diff --git a/src/nvim/event/time.h b/src/nvim/event/time.h index 7882b2b627..14df176ea3 100644 --- a/src/nvim/event/time.h +++ b/src/nvim/event/time.h @@ -13,6 +13,7 @@ struct time_watcher { void *data; time_cb cb, close_cb; Queue *events; + bool blockable; }; #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit