diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2016-06-05 10:49:33 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2016-06-29 18:57:18 +0200 |
commit | 2c39e0b03f083bac569901b62f0058559bacfc63 (patch) | |
tree | 8f33e8e185bfad3a6efa590bf637c74518beaa01 /src | |
parent | 204f557a11e27b20a0343788500b4bdda36d4c3f (diff) | |
download | rneovim-2c39e0b03f083bac569901b62f0058559bacfc63.tar.gz rneovim-2c39e0b03f083bac569901b62f0058559bacfc63.tar.bz2 rneovim-2c39e0b03f083bac569901b62f0058559bacfc63.zip |
timers: make timers work with zero timeout
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f5cffbc3e1..f45612a886 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -435,6 +435,7 @@ typedef struct { TimeWatcher tw; int timer_id; int repeat_count; + long timeout; bool stopped; ufunc_T *callback; } timer_T; @@ -16655,6 +16656,7 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv) timer = xmalloc(sizeof *timer); timer->stopped = false; timer->repeat_count = repeat; + timer->timeout = timeout; timer->timer_id = last_timer_id++; timer->callback = func; @@ -16709,6 +16711,14 @@ static void timer_due_cb(TimeWatcher *tw, void *data) call_user_func(timer->callback, ARRAY_SIZE(argv), argv, &rettv, curwin->w_cursor.lnum, curwin->w_cursor.lnum, NULL); clear_tv(&rettv); + + if (!timer->stopped && timer->timeout == 0) { + // special case: timeout=0 means the callback will be + // invoked again on the next event loop tick. + // we don't use uv_idle_t to not spin the event loop + // when the main loop is blocked. + time_watcher_start(&timer->tw, timer_due_cb, 0, 0); + } } static void timer_stop(timer_T *timer) |