Last active
October 19, 2021 15:52
-
-
Save Meorawr/1621c437302aea446cef5f6d08c0e5c6 to your computer and use it in GitHub Desktop.
Event Continuation Registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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