ISSUE
When attaching a catch after a promise is added to the janitor through Janitor:AddPromise(), it will still throw an unhandled rejection:
local Packages = game.ReplicatedStorage.src.Packages
local Janitor = require(Packages.Janitor)
local Promise = require(Packages.Promise)
local janitor = Janitor.new()
janitor:AddPromise(Promise.new(function(resolve, reject)
task.wait(2)
reject("THIS REJECTED")
end)):catch(warn)
FIX
The fix seems to be changing the return in Janitor:AddPromise() to the below:
-- newPromise:finally(function()
-- if Get(self, uniqueId) == newPromise then
-- Remove(self, uniqueId)
-- end
-- end)
-- return newPromise :: never
return newPromise:finally(function()
if Get(self, uniqueId) == newPromise then
Remove(self, uniqueId)
end
end)