-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.lua
More file actions
39 lines (33 loc) · 1.07 KB
/
example.lua
File metadata and controls
39 lines (33 loc) · 1.07 KB
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
local scheduler = require("scheduler")
local sleep = scheduler.sleep
--// Coroutine c1
local c1id = scheduler.resume(coroutine.create(function()
while sleep(0.4) do
print("Hello from coroutine 1!")
end
end))
--// Coroutine c2
scheduler.resume(coroutine.create(function()
while sleep(0.5) do
print("Hello from coroutine 2!")
end
end))
--// Performance printing of coroutine c1
scheduler.resume(coroutine.create(function()
while sleep(1) do
local perfData = scheduler.tasks[c1id].performance
if perfData.calls > 0 then
print("Coroutine 1 performance\nTotal calls | AVG CPU Time | Total CPU time\n" ..
perfData.calls .. " " ..
string.format("%.5f", perfData.cpuTimeSpent / perfData.calls * 1000) .. " ms " ..
string.format("%.5f", perfData.cpuTimeSpent * 1000) .. " ms")
end
end
end))
--// Garbage collection
scheduler.resume(coroutine.create(function()
while sleep(1) do
collectgarbage("collect")
end
end))
while scheduler.run() do end