From ae208dc380808ff1aef39929a0e897e881571d43 Mon Sep 17 00:00:00 2001 From: William Boman Date: Fri, 13 Oct 2023 21:14:29 +0200 Subject: refactor: standardize constructors and improve inheritance construction --- lua/mason-core/async/init.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lua/mason-core/async/init.lua') 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 -- cgit v1.2.3-70-g09d2