Lua-cURLv3/test/test_multi_nested_callback.lua
Alexey Melnichuk 56b4d05c17 Fix. Set Lua in callback context in info_read function.
Fix. Support nested callbacks.
Fix. Cleanup easy references when calls multi::close.
Add. `__tostring` method for handles.
2016-09-28 12:54:44 +03:00

48 lines
841 B
Lua

local curl = require "lcurl"
-- for Lua 5.1 compat
local function co_running()
local co, main = coroutine.running()
if main == true then return nil end
return co
end
local state, called = true, 0
local thread, msg
local function check_thread()
if thread ~= co_running() then
print(msg)
os.exit(-1)
end
end
local m; m = curl.multi{
timerfunction = function()
check_thread()
called = called + 1
if state then state = false
thread = coroutine.create(function()
local e = curl.easy()
m:add_handle(e)
end)
msg = 'add from coroutine'
coroutine.resume(thread)
assert(called == 2)
msg, thread = 'add from main'
local e = curl.easy()
m:add_handle(e)
assert(called == 3)
end
end
}
e = curl.easy()
m:add_handle(e)
assert(called == 3)