Skip to content

Commit

Permalink
👍 Do NOT use timer_start in wait_async
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Dec 30, 2023
1 parent 7917a57 commit c946bcc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
20 changes: 3 additions & 17 deletions autoload/denops/plugin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ function! denops#plugin#wait_async(plugin, callback) abort
if s:loaded_plugins[a:plugin] isnot# 0
return
endif
" Some features behave differently in functions invoked from timer_start()
" so use it even for immediate execution to keep consistent behavior.
call timer_start(0, { -> a:callback() })
call a:callback()
return
endif
let l:callbacks = get(s:load_callbacks, a:plugin, [])
Expand Down Expand Up @@ -157,13 +155,6 @@ function! s:find_plugin(plugin) abort
throw printf('No denops plugin for "%s" exists', a:plugin)
endfunction

" Split function to create new callstack independent for loop,
" because overwrited callback references when
" before timer processing timings.
function! s:delay_callback(callback) abort
call timer_start(0, { -> a:callback() })
endfunction

function! s:DenopsSystemPluginRegister() abort
let l:plugin = matchstr(expand('<amatch>'), 'DenopsSystemPluginRegister:\zs.*')
execute printf('doautocmd <nomodeline> User DenopsPluginRegister:%s', l:plugin)
Expand All @@ -178,13 +169,8 @@ function! s:DenopsSystemPluginPost() abort
let l:plugin = matchstr(expand('<amatch>'), 'DenopsSystemPluginPost:\zs.*')
let s:loaded_plugins[l:plugin] = 0
if has_key(s:load_callbacks, l:plugin)
let l:callbacks = remove(s:load_callbacks, l:plugin)
" Vim uses FILO for a task execution registered by timer_start().
" That's why reverse 'callbacks' in the case of Vim to keep consistent
" behavior.
let l:callbacks = has('nvim') ? l:callbacks : reverse(l:callbacks)
for l:Callback in l:callbacks
call s:delay_callback(l:Callback)
for l:Callback in remove(s:load_callbacks, l:plugin)
call l:Callback()
endfor
endif
execute printf('doautocmd <nomodeline> User DenopsPluginPost:%s', l:plugin)
Expand Down
3 changes: 1 addition & 2 deletions doc/denops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ denops#plugin#wait_async({plugin}, {callback})
{callback}. It invokes the {callback} immediately when the {plugin}
plugin is already loaded. If this function is called multiple times
for same {plugin} plugin, callbacks registered for the plugin are
called in order of registration. Note that the {callback} is called
from |timer_start()| in any cases to keep consistent behavior.
called in order of registration.

*denops#plugin#discover()*
denops#plugin#discover()
Expand Down

0 comments on commit c946bcc

Please sign in to comment.