diff --git a/lib/init.lua b/lib/init.lua index 34efa19..e6ceb72 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -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)