import { fn } from "https://deno.land/x/ddc_vim@v4.1.0/deps.ts";
const { timer_start } = fn;
Create a timer and return the timer ID.
{time} is the waiting time in milliseconds. This is the minimum time before invoking the callback. When the system is busy or Vim is not waiting for input the time will be longer. Zero can be used to execute the callback when Vim is back in the main loop.
{callback} is the function to call. It can be the name of a
function or a Funcref
. It is called with one argument, which
is the timer ID. The callback is only invoked when Vim is
waiting for input.
If you want to show a message look at popup_notification()
to avoid interfering with what the user is doing.
{options} is a dictionary. Supported entries: "repeat" Number of times to repeat calling the callback. -1 means forever. When not present the callback will be called once. If the timer causes an error three times in a row the repeat is cancelled. This avoids that Vim becomes unusable because of all the error messages.
Returns -1 on error.
Example:
func MyHandler(timer)
echo 'Handler called'
endfunc
let timer = timer_start(500, 'MyHandler',
\ {'repeat': 3})
This will invoke MyHandler() three times at 500 msec intervals.
Can also be used as a method
:
GetMsec()->timer_start(callback)
Not available in the sandbox
.
only available when compiled with the +timers
feature