Call cancellation hook immediately if already cancelled

This commit is contained in:
Eryn Lynn 2018-11-09 00:00:40 -05:00
parent cda921e793
commit 601127071c

View file

@ -170,8 +170,12 @@ function Promise.new(callback, parent)
local function onCancel(cancellationHook)
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
end
end
local _, result = wpcallPacked(callback, resolve, reject, onCancel)
local ok = result[1]