mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 23:50:03 +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,8 +170,12 @@ function Promise.new(callback, parent)
|
||||||
local function onCancel(cancellationHook)
|
local function onCancel(cancellationHook)
|
||||||
assert(type(cancellationHook) == "function", "onCancel must be called with a function as its first argument.")
|
assert(type(cancellationHook) == "function", "onCancel must be called with a function as its first argument.")
|
||||||
|
|
||||||
|
if self._status == Promise.Status.Cancelled then
|
||||||
|
cancellationHook()
|
||||||
|
else
|
||||||
self._cancellationHook = cancellationHook
|
self._cancellationHook = cancellationHook
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local _, result = wpcallPacked(callback, resolve, reject, onCancel)
|
local _, result = wpcallPacked(callback, resolve, reject, onCancel)
|
||||||
local ok = result[1]
|
local ok = result[1]
|
||||||
|
|
Loading…
Reference in a new issue