Here's what I would do.
Lua Code:
local LevelTimes={};-- For this example, we'll say this is loaded from SavedVar
local EventFrame=CreateFrame("Frame");
EventFrame:RegisterEvent("PLAYER_LEVEL_UP");
EventFrame:RegisterEvent("TIME_PLAYED_MSG");
EventFrame:SetScript("OnEvent",function(self,event,...)
if event=="PLAYER_LEVEL_UP" then
self.WaitingForPlayTime=true;-- Flag continuation
RequestTimePlayed();
elseif event=="TIME_PLAYED_MSG" and self.WaitingForPlayTime then
self.WaitingForPlayTime=false;-- Clear flag
LevelTimes[UnitLevel("player")-1]=...;-- Record time to complete level
end
end);