add coroutine
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
server {
|
||||
# https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx#
|
||||
# server_name $servername;
|
||||
server_name "test.localhost";
|
||||
listen 8088;
|
||||
|
||||
set $resty_loc "/usr/local/opt/openresty";
|
||||
|
||||
location /api/ngx/test/co {
|
||||
content_by_lua_file $resty_loc/nginx/scripts/tests/co.lua;
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
@@ -22,6 +22,10 @@ echo $openresty_lua_scripts_dir
|
||||
mkdir -p $openresty_lua_scripts_dir
|
||||
# -- Copy scripts file
|
||||
cp scripts/*.lua $openresty_lua_scripts_dir
|
||||
# -- Copy tests
|
||||
mkdir -p $openresty_lua_scripts_dir/tests/
|
||||
cp test_scripts/*.lua $openresty_lua_scripts_dir/tests/
|
||||
|
||||
# -- Replace scripts path in file
|
||||
sed -i -e "s|<SCRIPT_PATH>|$openresty_lua_scripts_dir|" \
|
||||
"$openresty_lua_scripts_dir"/combine.lua \
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
local function sleep(n)
|
||||
os.execute("sleep " .. tonumber(n))
|
||||
end
|
||||
|
||||
local co = coroutine.create(function(x)
|
||||
sleep(3)
|
||||
print("co -> ", x)
|
||||
end)
|
||||
|
||||
coroutine.resume(co, 42)
|
||||
|
||||
ngx.say("main")
|
||||
|
||||
Reference in New Issue
Block a user