diff options
Diffstat (limited to 'lua/mason-core/async/init.lua')
| -rw-r--r-- | lua/mason-core/async/init.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lua/mason-core/async/init.lua b/lua/mason-core/async/init.lua index 63d4ec94..56d86170 100644 --- a/lua/mason-core/async/init.lua +++ b/lua/mason-core/async/init.lua @@ -6,8 +6,12 @@ local exports = {} local Promise = {} Promise.__index = Promise -function Promise.new(resolver) - return setmetatable({ resolver = resolver, has_resolved = false }, Promise) +function Promise:new(resolver) + local instance = {} + setmetatable(instance, self) + instance.resolver = resolver + instance.has_resolved = false + return instance end ---@param success boolean @@ -27,7 +31,7 @@ function Promise:__call(callback) end local function await(resolver) - local ok, value = co.yield(Promise.new(resolver)) + local ok, value = co.yield(Promise:new(resolver)) if not ok then error(value[1], 0) end @@ -156,7 +160,7 @@ end ---@param suspend_fns async fun()[] ---@param mode '"first"' | '"all"' local function wait(suspend_fns, mode) - local channel = require("mason-core.async.control").OneShotChannel.new() + local channel = require("mason-core.async.control").OneShotChannel:new() if #suspend_fns == 0 then return end |
