add an example script for the uloop lua binding
This commit is contained in:
parent
a81cb397ef
commit
0a81131257
2 changed files with 55 additions and 0 deletions
44
examples/uloop-example.lua
Executable file
44
examples/uloop-example.lua
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/env lua
|
||||||
|
|
||||||
|
local uloop = require("uloop")
|
||||||
|
uloop.init()
|
||||||
|
|
||||||
|
-- timer example 1
|
||||||
|
local timer
|
||||||
|
function t()
|
||||||
|
print("1000 ms timer run");
|
||||||
|
timer:set(1000)
|
||||||
|
end
|
||||||
|
timer = uloop.timer(t)
|
||||||
|
timer:set(1000)
|
||||||
|
|
||||||
|
-- timer example 2
|
||||||
|
uloop.timer(function() print("2000 ms timer run"); end, 2000)
|
||||||
|
|
||||||
|
-- timer example 3
|
||||||
|
uloop.timer(function() print("3000 ms timer run"); end, 3000):cancel()
|
||||||
|
|
||||||
|
-- process
|
||||||
|
function p1(r)
|
||||||
|
print("Process 1 completed")
|
||||||
|
print(r)
|
||||||
|
end
|
||||||
|
|
||||||
|
function p2(r)
|
||||||
|
print("Process 2 completed")
|
||||||
|
print(r)
|
||||||
|
end
|
||||||
|
|
||||||
|
uloop.timer(
|
||||||
|
function()
|
||||||
|
uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=1"}, p1)
|
||||||
|
end, 1000
|
||||||
|
)
|
||||||
|
uloop.timer(
|
||||||
|
function()
|
||||||
|
uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=2"}, p2)
|
||||||
|
end, 2000
|
||||||
|
)
|
||||||
|
|
||||||
|
uloop.run()
|
||||||
|
|
11
examples/uloop_pid_test.sh
Executable file
11
examples/uloop_pid_test.sh
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo $0 $*
|
||||||
|
echo Environment:
|
||||||
|
env
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
echo "stopping child"
|
||||||
|
|
||||||
|
exit 5
|
Loading…
Reference in a new issue