utils: add little-endian swap helpers
[project/libubox.git] / examples / uloop-example.lua
1 #!/usr/bin/env lua
2
3 local uloop = require("uloop")
4 uloop.init()
5
6 -- timer example 1
7 local timer
8 function t()
9         print("1000 ms timer run");
10         timer:set(1000)
11 end
12 timer = uloop.timer(t)
13 timer:set(1000)
14
15 -- timer example 2
16 uloop.timer(function() print("2000 ms timer run"); end, 2000)
17
18 -- timer example 3
19 uloop.timer(function() print("3000 ms timer run"); end, 3000):cancel()
20
21 -- process
22 function p1(r)
23         print("Process 1 completed")
24         print(r)
25 end
26
27 function p2(r)
28         print("Process 2 completed")
29         print(r)
30 end
31
32 uloop.timer(
33         function()
34                 uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=1"}, p1)
35         end, 1000
36 )
37 uloop.timer(
38         function()
39                 uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=2"}, p2)
40         end, 2000
41 )
42
43 uloop.run()
44