Skip to content

Instantly share code, notes, and snippets.

@Meorawr
Last active October 19, 2021 15:52
Show Gist options
  • Save Meorawr/1621c437302aea446cef5f6d08c0e5c6 to your computer and use it in GitHub Desktop.
Save Meorawr/1621c437302aea446cef5f6d08c0e5c6 to your computer and use it in GitHub Desktop.
Event Continuation Registry
local ContinuationRegistry = Mixin(CreateFrame("Frame"), CallbackRegistryMixin);
local function ProcessContinuations(registry, event)
ContinuationRegistry:UnregisterEvent(event);
ContinuationRegistry:TriggerEvent(event);
end
local function InvokeContinuation(func, event)
ContinuationRegistry:UnregisterCallback(event, func);
func(); -- May error, this is fine.
end
function ContinueOnNextEvent(event, func, ...)
ContinuationRegistry:RegisterCallback(event, InvokeContinuation, GenerateClosure(func, ...), event);
ContinuationRegistry:RegisterEvent(event);
end
ContinuationRegistry:OnLoad();
ContinuationRegistry:SetUndefinedEventsAllowed(true);
ContinuationRegistry:SetScript("OnEvent", ProcessContinuations);
---
function ContinueWhenOutOfCombat(func, ...)
if InCombatLockdown() then
ContinueOnNextEvent("PLAYER_REGEN_ENABLED", func, ...);
else
func(...);
end
end
ContinueWhenOutOfCombat(print, 1, 2, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment