aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-04-02 00:15:48 +0200
committerGitHub <noreply@github.com>2023-04-02 00:15:48 +0200
commit2e35781f5ee020fac6182b4494fdf2f12f3a9bbf (patch)
tree007649bea851c2b65d04fc685fb7a7ff4b16ff30
parentfix(ui): remove new lines from error (#1167) (diff)
downloadmason-2e35781f5ee020fac6182b4494fdf2f12f3a9bbf.tar
mason-2e35781f5ee020fac6182b4494fdf2f12f3a9bbf.tar.gz
mason-2e35781f5ee020fac6182b4494fdf2f12f3a9bbf.tar.bz2
mason-2e35781f5ee020fac6182b4494fdf2f12f3a9bbf.tar.lz
mason-2e35781f5ee020fac6182b4494fdf2f12f3a9bbf.tar.xz
mason-2e35781f5ee020fac6182b4494fdf2f12f3a9bbf.tar.zst
mason-2e35781f5ee020fac6182b4494fdf2f12f3a9bbf.zip
fix(registry): use oneshot channel for updating registry (#1168)
-rw-r--r--lua/mason-core/async/control.lua52
-rw-r--r--lua/mason-core/async/init.lua40
-rw-r--r--lua/mason-registry/init.lua21
-rw-r--r--lua/mason-registry/installer.lua38
4 files changed, 85 insertions, 66 deletions
diff --git a/lua/mason-core/async/control.lua b/lua/mason-core/async/control.lua
index 3252c070..df2627f6 100644
--- a/lua/mason-core/async/control.lua
+++ b/lua/mason-core/async/control.lua
@@ -5,28 +5,21 @@ local Condvar = {}
Condvar.__index = Condvar
function Condvar.new()
- return setmetatable({ handles = {}, queue = {}, is_notifying = false }, Condvar)
+ return setmetatable({ handles = {} }, Condvar)
end
---@async
function Condvar:wait()
a.wait(function(resolve)
- if self.is_notifying then
- self.queue[resolve] = true
- else
- self.handles[resolve] = true
- end
+ self.handles[#self.handles + 1] = resolve
end)
end
function Condvar:notify_all()
- self.is_notifying = true
- for handle in pairs(self.handles) do
- handle()
+ for _, handle in ipairs(self.handles) do
+ pcall(handle)
end
- self.handles = self.queue
- self.queue = {}
- self.is_notifying = false
+ self.handles = {}
end
local Permit = {}
@@ -69,7 +62,42 @@ function Semaphore:acquire()
return Permit.new(self)
end
+---@class OneShotChannel
+---@field has_sent boolean
+---@field value any
+---@field condvar Condvar
+local OneShotChannel = {}
+OneShotChannel.__index = OneShotChannel
+
+function OneShotChannel.new()
+ return setmetatable({
+ has_sent = false,
+ value = nil,
+ condvar = Condvar.new(),
+ }, OneShotChannel)
+end
+
+function OneShotChannel:is_closed()
+ return self.has_sent
+end
+