Skip to content

Commit

Permalink
Updated AddPromise to cancel properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
howmanysmall committed Nov 5, 2021
1 parent a8266e1 commit 855db08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/GetPromiseLibrary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")

local LOCATIONS_TO_SEARCH = {ReplicatedFirst, ReplicatedStorage, ServerScriptService, ServerStorage, script.Parent.Parent}
local LOCATIONS_TO_SEARCH = {script.Parent.Parent, ReplicatedFirst, ReplicatedStorage, ServerScriptService, ServerStorage}

local function FindFirstDescendantWithNameAndClassName(Parent: Instance, Name: string, ClassName: string)
for _, Descendant in ipairs(Parent:GetDescendants()) do
Expand Down
11 changes: 10 additions & 1 deletion src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,16 @@ function Janitor:AddPromise(PromiseObject)

if PromiseObject:getStatus() == Promise.Status.Started then
local Id = newproxy(false)
local NewPromise = self:Add(Promise.resolve(PromiseObject), "cancel", Id)
local NewPromise = self:Add(Promise.new(function(Resolve, _, OnCancel)
if OnCancel(function()
PromiseObject:cancel()
end) then
return
end

Resolve(PromiseObject)
end), "cancel", Id)

NewPromise:finallyCall(self.Remove, self, Id)
return NewPromise
else
Expand Down
2 changes: 1 addition & 1 deletion wally.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
name = "howmanysmall/janitor"
realm = "shared"
registry = "https://github.com/UpliftGames/wally-index"
version = "1.13.13"
version = "1.13.14"

[dependencies]

0 comments on commit 855db08

Please sign in to comment.