-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecuteTimer.df
65 lines (50 loc) · 1.48 KB
/
ExecuteTimer.df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class ExecuteTimer
local m_endTime
local m_duration
local m_isRunning = 0
local m_started = 0
local m_stoppedTime
local string m_executeActions
function m_WaitForTimeout()
while (m_isRunning)
if (SysTime() >= m_endTime)
for (Private.Counter = 0, Counter < NumRows(m_executeActions), Counter++)
Execute(m_executeActions[Counter])
endfor
m_isRunning = 0
m_started = 0
endif
endwhile
endfunction
function Resume()
// Make sure to call this method in a separate thread as it is blocking.
if (m_isRunning || !m_started)
return 0 // Failure.
endif
m_endTime += SysTime() - m_stoppedTime
m_isRunning = 1
m_WaitForTimeout()
return 1 // Success.
endfunction
function Start(string executeActions, duration)
// Make sure to call this method in a separate thread as it is blocking.
if (m_isRunning)
return 0 // Failure.
endif
m_duration = duration
m_endTime = SysTime() + m_duration
m_isRunning = 1
m_started = 1
m_executeActions = executeActions
m_WaitForTimeout()
return 1 // Success.
endfunction
function Stop()
if (!m_isRunning)
return 0 // Failure.
endif
m_isRunning = 0
m_stoppedTime = SysTime()
return 1 // Success.
endfunction
endclass