mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Call cancellation hook immediately if already cancelled
This commit is contained in:
parent
cda921e793
commit
601127071c
1 changed files with 5 additions and 1 deletions
|
@ -170,7 +170,11 @@ function Promise.new(callback, parent)
|
|||
local function onCancel(cancellationHook)
|
||||
assert(type(cancellationHook) == "function", "onCancel must be called with a function as its first argument.")
|
||||
|
||||
self._cancellationHook = cancellationHook
|
||||
if self._status == Promise.Status.Cancelled then
|
||||
cancellationHook()
|
||||
else
|
||||
self._cancellationHook = cancellationHook
|
||||
end
|
||||
end
|
||||
|
||||
local _, result = wpcallPacked(callback, resolve, reject, onCancel)
|
||||
|
|
Loading…
Reference in a new issue