Skip to content

Commit

Permalink
👍 Add timeout feature to denops#plugin#wait()
Browse files Browse the repository at this point in the history
Close #174
  • Loading branch information
lambdalisue committed Feb 19, 2022
1 parent 93f36f9 commit a38b752
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions autoload/denops/plugin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@ function! denops#plugin#wait(plugin, ...) abort
endif
let options = extend({
\ 'interval': g:denops#plugin#wait_interval,
\ 'timeout': g:denops#plugin#wait_timeout,
\}, a:0 ? a:1 : {},
\)
let expr = printf('sleep %dm', options.interval)
let t = options.timeout
let s = reltime()
while !has_key(s:loaded_plugins, a:plugin)
if reltimefloat(reltime(s)) * 1000 > t
let m = printf(
\ "TimeoutError: '%s' took more than %d milliseconds to initialized",
\ a:plugin,
\ t,
\)
let s:loaded_plugins[a:plugin] = m
call s:echoerr(m)
return
endif
execute expr
endwhile
endfunction
Expand Down Expand Up @@ -142,3 +155,4 @@ augroup denops_autoload_plugin_internal
augroup END

let g:denops#plugin#wait_interval = get(g:, 'denops#plugin#wait_interval', 10)
let g:denops#plugin#wait_timeout = get(g:, 'denops#plugin#wait_timeout', 5000)
4 changes: 4 additions & 0 deletions doc/denops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ VARIABLE *denops-variable*
Interval in milliseconds for |denops#plugin#wait()|.
Default: 10

*g:denops#plugin#wait_timeout*
Timeout in milliseconds for |denops#plugin#wait()|.
Default: 5000

-----------------------------------------------------------------------------
FUNCTION *denops-function*

Expand Down

0 comments on commit a38b752

Please sign in to comment.