Azlier
Old World Ghost
- Reaction score
- 461
It seems that everything but zero second timers has been done in the best way. TimerUtils handles low frequency timers, T32 handles high frequency "timers".
Is this any good?
Is this any good?
JASS:
// OnZero, by Azlier
// OnZero simply runs a function after zero seconds in the most efficient way possible.
// The given function must return a boolean. Any boolean. For efficiency reasons.
// Who cares about good API?
// Syntax:
// call OnZero(function FunctionToRunAfterZeroSeconds)
library OnZero initializer Init
globals
private trigger t = CreateTrigger()
private boolean b
private timer ti = CreateTimer()
endglobals
function OnZero takes code c returns nothing
set b = true
call ResumeTimer(ti)
call TriggerAddCondition(t, Filter(c))
endfunction
private function Fire takes nothing returns nothing
if b then
call PauseTimer(ti)
set b = false
call TriggerEvaluate(t)
call TriggerClearConditions(t)
endif
endfunction
private function Init takes nothing returns nothing
call TimerStart(ti, 0, true, function Fire)
call PauseTimer(ti)
endfunction
endlibrary