2016-03-13 18:06 GMT+03:00 Bram Moolenaar <[email protected]>:
>
> I have a note about adding a way that a callback can be invoked at a
> certain time. I would like to know how this is going to be used, what
> the requirements for this feature are.
>
> I imagine there are two kinds of timers:
>
> 1. One-time: After N msec the callback is invoked.
> 2. Repating: invoke the callback every N msec
>
> For both this will happen while waiting for a character, thus the actual
> wait time will be longer if the user is typing.
>
> Example:
>
> let timer = timer_add({time}, {callback} [, {repeats} [, {cookie}]])
> call timer_stop(timer)
>
> func MyTimerCallback(timer, cookie)
>
> Would that satisfy the need?
>
> I think it would be good that if the callback causes an error the timer
> is stopped.
I would say that dictionary is better then four arguments:
1. It enables feature used by Neovim for callbacks: dictionary that
defined timer is passed as a `self` dictionary to a dictionary
function, while in your variant dictionary functions cannot be used at
all.
2. This allows adding more options in the future. E.g. alter error
handling, silence function or add a timeout after which callback is
interrupted.
3. Dictionary may serve both as `timer` and as a `cookie`.
E.g.
let def = {
\ 'interval': Number|Float (seconds),
\ 'callback': String|Funcref,
\ 'repeats': Number (optional),
\ 'Cookie': … (keys matching `^[a-z]\+$` are reserved for Vim)}
call timer_add(def)
call timer_stop(def)
function Callback() dict
endfunction
>
> --
> Q. What happens to programmers when they die?
> A: MS-Windows programmers are reinstalled. C++ programmers become undefined,
> anyone who refers to them will die as well. Java programmers reincarnate
> after being garbage collected, unless they are in permgen, in which case
> they become zombies. Zimbu programmers leave a stack trace that tells us
> exactly where they died and how they got there.
>
> /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
> /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
> \\\ an exciting new programming language -- http://www.Zimbu.org ///
> \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.