mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Make Promise.new refer to the created promise as
This commit is contained in:
parent
639f0e8419
commit
9bda3e68ea
1 changed files with 6 additions and 6 deletions
12
lib/init.lua
12
lib/init.lua
|
@ -109,7 +109,7 @@ Promise.Status = {
|
|||
end)
|
||||
]]
|
||||
function Promise.new(callback)
|
||||
local promise = {
|
||||
local self = {
|
||||
-- Used to locate where a promise was created
|
||||
_source = debug.traceback(),
|
||||
|
||||
|
@ -134,25 +134,25 @@ function Promise.new(callback)
|
|||
_queuedReject = {},
|
||||
}
|
||||
|
||||
setmetatable(promise, Promise)
|
||||
setmetatable(self, Promise)
|
||||
|
||||
local function resolve(...)
|
||||
promise:_resolve(...)
|
||||
self:_resolve(...)
|
||||
end
|
||||
|
||||
local function reject(...)
|
||||
promise:_reject(...)
|
||||
self:_reject(...)
|
||||
end
|
||||
|
||||
local _, result = wpcallPacked(callback, resolve, reject)
|
||||
local ok = result[1]
|
||||
local err = result[2]
|
||||
|
||||
if not ok and promise._status == Promise.Status.Started then
|
||||
if not ok and self._status == Promise.Status.Started then
|
||||
reject(err)
|
||||
end
|
||||
|
||||
return promise
|
||||
return self
|
||||
end
|
||||
|
||||
--[[
|
||||
|
|
Loading…
Reference in a new issue