Skip to content

Commit

Permalink
fix: remove local rock outside of sync query_installed_rocks callback (
Browse files Browse the repository at this point in the history
…#21)

* fix: remove local rock outside of sync query_installed_rocks callback

* fix: replace nio.event with nio.future

---------

Co-authored-by: Drake Bott <[email protected]>
  • Loading branch information
bottd and bottd authored Jun 12, 2024
1 parent 4bc4a22 commit 3ee5e96
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions lua/rocks-dev/local-rock-handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@ function rock_handler.get_sync_callback(rock)
---@param report_progress fun(message: string)
---@param report_error fun(message: string)
return nio.create(function(report_progress, report_error)
local future = nio.control.future()
api.query_installed_rocks(function(rocks)
if rocks[rock.name] then
local ok = pcall(operations.remove(rock.name).wait)
future.set(true)
else
future.set(false)
end
end)

if not ok then
report_error(("rocks-dev: Failed to remove %s"):format(rock.name))
return
end
local remove_local_rock = future.wait()

report_progress(("rocks-dev: Hotswapped %s"):format(rock.name))
if remove_local_rock then
local ok = pcall(nio.create(operations.remove(rock.name).wait))
if not ok then
report_error(("rocks-dev: Failed to remove %s"):format(rock.name))
return
end
end)
report_progress(("rocks-dev: Hotswapped %s"):format(rock.name))
end
end, 2)
end
end
Expand Down

0 comments on commit 3ee5e96

Please sign in to comment.