Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1893,30 +1893,47 @@ function Promise.prototype:_reject(...)
self:_finalize()
end

--[[
Calls any :finally handlers. We need this to be a separate method and
queue because we must call all of the finally callbacks upon a success,
failure, *and* cancellation.
]]
function Promise.prototype:_finalize()
for _, callback in ipairs(self._queuedFinally) do
-- Purposefully not passing values to callbacks here, as it could be the
-- resolved values, or rejected errors. If the developer needs the values,
-- they should use :andThen or :catch explicitly.
coroutine.wrap(callback)(self._status)
do
local threadsToClose = {}
local closingTask = nil

local function closeThreads()
closingTask = nil
local threads = threadsToClose
threadsToClose = {}
for _, thread in threads do
coroutine.close(thread)
end
end

self._queuedFinally = nil
self._queuedReject = nil
self._queuedResolve = nil
--[[
Calls any :finally handlers. We need this to be a separate method and
queue because we must call all of the finally callbacks upon a success,
failure, *and* cancellation.
]]
function Promise.prototype:_finalize()
for _, callback in ipairs(self._queuedFinally) do
-- Purposefully not passing values to callbacks here, as it could be the
-- resolved values, or rejected errors. If the developer needs the values,
-- they should use :andThen or :catch explicitly.
coroutine.wrap(callback)(self._status)
end

self._queuedFinally = nil
self._queuedReject = nil
self._queuedResolve = nil

-- Clear references to other Promises to allow gc
if not Promise.TEST then
self._parent = nil
self._consumers = nil
end
-- Clear references to other Promises to allow gc
if not Promise.TEST then
self._parent = nil
self._consumers = nil
end

task.defer(coroutine.close, self._thread)
table.insert(threadsToClose, self._thread)
if not closingTask then
closingTask = task.defer(closeThreads)
end
end
end

--[=[
Expand Down
2 changes: 1 addition & 1 deletion rotriever.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "Promise"
version = "3.5.0"
version = "3.5.1"
authors = ["evaera"]
license = "MIT"
content_root = "lib"
Expand Down