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