@@ -37,44 +37,46 @@ function M.call_api(url, method, body)
3737 if err then
3838 local ok , pcall_err = pcall (call_promise .reject , call_promise , err )
3939 if not ok then
40- vim .notify (' Error while handling API error response: ' .. vim .inspect (pcall_err ))
40+ vim .schedule (function ()
41+ vim .notify (' Error while handling API error response: ' .. vim .inspect (pcall_err ))
42+ end )
4143 end
42- state .job_count = state .job_count - 1
4344 else
4445 local ok , pcall_err = pcall (call_promise .resolve , call_promise , result )
4546 if not ok then
46- vim .notify (' Error while handling API response: ' .. vim .inspect (pcall_err ))
47+ vim .schedule (function ()
48+ vim .notify (' Error while handling API response: ' .. vim .inspect (pcall_err ))
49+ end )
4750 end
48- state .job_count = state .job_count - 1
4951 end
5052 end )
5153 end ,
5254 on_error = function (err )
5355 local ok , pcall_err = pcall (call_promise .reject , call_promise , err )
5456 if not ok then
55- vim .notify (' Error while handling API on_error: ' .. vim .inspect (pcall_err ))
57+ vim .schedule (function ()
58+ vim .notify (' Error while handling API on_error: ' .. vim .inspect (pcall_err ))
59+ end )
5660 end
57- state .job_count = state .job_count - 1
5861 end ,
5962 }
6063
6164 if body ~= nil then
6265 opts .body = body and vim .json .encode (body ) or ' {}'
6366 end
6467
65- -- For promise tracking, remove promises that complete from requests
66- -- NOTE: can remove the request tracking code when we're happy with
67- -- request reliability
6868 local request_entry = { opts , call_promise }
6969 table.insert (M .requests , request_entry )
7070
71+ -- Remove completed promises from list, update job_count
7172 local function remove_from_requests ()
7273 for i , entry in ipairs (M .requests ) do
7374 if entry == request_entry then
7475 table.remove (M .requests , i )
7576 break
7677 end
7778 end
79+ state .job_count = # M .requests
7880 end
7981
8082 call_promise :and_then (function (result )
0 commit comments