fix(lua): add wait to socket connect
This commit is contained in:
@@ -4,6 +4,19 @@ local logger = require("neotest.logging")
|
||||
|
||||
local M = {}
|
||||
|
||||
---@async
|
||||
---Calls callback after a certain time using uv.timer
|
||||
---@param sleep_ms integer
|
||||
---@param callback function
|
||||
local function async_sleep(sleep_ms, callback)
|
||||
local timer = assert(vim.uv.new_timer())
|
||||
timer:start(sleep_ms, 0, function()
|
||||
timer:stop()
|
||||
timer:close()
|
||||
callback()
|
||||
end)
|
||||
end
|
||||
|
||||
---@async
|
||||
---Add test instances for path in root to positions
|
||||
---@param positions neotest.Tree
|
||||
@@ -71,10 +84,12 @@ local function get_socket_path(cmd, messages, callback)
|
||||
|
||||
-- 2. Connect to the unix socket
|
||||
local client = assert(vim.uv.new_pipe(false))
|
||||
|
||||
client:connect(socket_path, function(err)
|
||||
local function _handle_tests(err)
|
||||
if err ~= nil then
|
||||
vim.print("Error", err)
|
||||
async_sleep(500, function()
|
||||
client:connect(socket_path, _handle_tests)
|
||||
end)
|
||||
end
|
||||
-- 3. Send message(s)
|
||||
if type(messages) == "string" then
|
||||
@@ -92,7 +107,9 @@ local function get_socket_path(cmd, messages, callback)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
client:connect(socket_path, _handle_tests)
|
||||
end
|
||||
|
||||
---@async
|
||||
|
||||
Reference in New Issue
Block a user