aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2016-07-01 17:34:28 +0200
committerGitHub <noreply@github.com>2016-07-01 17:34:28 +0200
commit6f4f654231955bc655d0b8a92c21878429b8c446 (patch)
tree8e597e6425ad9d086ec6410843f1cbbcb792d458 /src
parentc8da12b9a6cd6060b02e06af90ea231e92724fec (diff)
parent5c754a2d2263e455ba3704cd278d52b254d195df (diff)
downloadrneovim-6f4f654231955bc655d0b8a92c21878429b8c446.tar.gz
rneovim-6f4f654231955bc655d0b8a92c21878429b8c446.tar.bz2
rneovim-6f4f654231955bc655d0b8a92c21878429b8c446.zip
Merge pull request #4880 from bfredl/zerotimer
make timers work correctly when timeout or repeat is zero
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index ac0daa226a..9a86c5765c 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;
@@ -16639,6 +16640,9 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv)
}
if (dict_find(dict, (char_u *)"repeat", -1) != NULL) {
repeat = get_dict_number(dict, (char_u *)"repeat");
+ if (repeat == 0) {
+ repeat = 1;
+ }
}
}
@@ -16656,6 +16660,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;
@@ -16710,6 +16715,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)