From 601127071cc00253d0f444c338d32013c96e8c00 Mon Sep 17 00:00:00 2001 From: Eryn Lynn Date: Fri, 9 Nov 2018 00:00:40 -0500 Subject: [PATCH] Call cancellation hook immediately if already cancelled --- lib/init.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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)