-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(registry): use oneshot channel for updating registry
- Loading branch information
1 parent
0669f0f
commit 01fddb2
Showing
4 changed files
with
85 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
local a = require "mason-core.async" | ||
local OneShotChannel = require("mason-core.async.control").OneShotChannel | ||
local Result = require "mason-core.result" | ||
local sources = require "mason-registry.sources" | ||
|
||
local M = {} | ||
|
||
---@type OneShotChannel? | ||
local update_channel | ||
|
||
---@async | ||
function M.run() | ||
if not update_channel or update_channel:is_closed() then | ||
update_channel = OneShotChannel.new() | ||
a.run(function() | ||
update_channel:send(Result.try(function(try) | ||
local updated_sources = {} | ||
for source in sources.iter { include_uninstalled = true } do | ||
source:get_installer():if_present(function(installer) | ||
try(installer():map_err(function(err) | ||
return ("%s failed to install: %s"):format(source, err) | ||
end)) | ||
table.insert(updated_sources, source) | ||
end) | ||
end | ||
return updated_sources | ||
end):on_success(function(updated_sources) | ||
if #updated_sources > 0 then | ||
require("mason-registry"):emit("update", updated_sources) | ||
end | ||
end)) | ||
end, function() end) | ||
end | ||
|
||
return update_channel:receive() | ||
end | ||
|
||
return M |