Skip to content

Commit

Permalink
Merge pull request #275 from kuuote/fix-multiple-wait_async
Browse files Browse the repository at this point in the history
🐛 Fix always use last callback at `wait_async()`
  • Loading branch information
lambdalisue authored Sep 7, 2023
2 parents a80e4d8 + b9cf1b0 commit 68f607d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion autoload/denops/plugin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ function! s:DenopsSystemPluginPre() abort
execute printf('doautocmd <nomodeline> User DenopsPluginPre:%s', l: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:DenopsSystemPluginPost() abort
let l:plugin = matchstr(expand('<amatch>'), 'DenopsSystemPluginPost:\zs.*')
let s:loaded_plugins[l:plugin] = 0
Expand All @@ -174,7 +181,7 @@ function! s:DenopsSystemPluginPost() abort
" behavior.
let l:callbacks = has('nvim') ? l:callbacks : reverse(l:callbacks)
for l:Callback in l:callbacks
call timer_start(0, { -> l:Callback() })
call s:delay_callback(l:Callback)
endfor
endif
execute printf('doautocmd <nomodeline> User DenopsPluginPost:%s', l:plugin)
Expand Down

0 comments on commit 68f607d

Please sign in to comment.