diff --git a/lua/rocks-dev/local-rock-handler.lua b/lua/rocks-dev/local-rock-handler.lua index 9395c1b..55bdd07 100644 --- a/lua/rocks-dev/local-rock-handler.lua +++ b/lua/rocks-dev/local-rock-handler.lua @@ -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