update network test and fix coroutines errors handling

This commit is contained in:
MihailRis 2025-09-14 14:11:34 +03:00
parent f531d2e358
commit 40eda93398
2 changed files with 46 additions and 24 deletions

View File

@ -1,19 +1,38 @@
local data = "hello, world" for i=1,3 do
local complete = false local text = ""
local complete = false
network.tcp_open(7645, function (client) for j=1,100 do
start_coroutine(function() text = text .. math.random(0, 9)
local received = client:recv(1024) end
if received then
assert (data, utf8.tostring(received)) local server = network.tcp_open(7645, function (client)
start_coroutine(function()
local received_text = ""
while client:is_alive() do
local received = client:recv(512)
if received then
received_text = received_text .. utf8.tostring(received)
end
coroutine.yield()
end
assert (received_text == text)
complete = true complete = true
end end, "client-listener")
coroutine.yield() end)
end, "client-listener")
end)
network.tcp_connect("localhost", 7645, function (socket) network.tcp_connect("localhost", 7645, function (socket)
socket:send(data) start_coroutine(function()
end) local ptr = 1
while ptr < #text do
local n = math.random(1, 20)
socket:send(string.sub(text, ptr, ptr + n - 1))
ptr = ptr + n
end
socket:close()
end, "data-sender")
end)
app.sleep_until(function () return complete end) app.sleep_until(function () return complete end)
server:close()
end

View File

@ -531,15 +531,18 @@ function start_coroutine(chunk, name)
local co = coroutine.create(function() local co = coroutine.create(function()
local status, error = xpcall(chunk, function(err) local status, error = xpcall(chunk, function(err)
local fullmsg = "error: "..string.match(err, ": (.+)").."\n"..debug.traceback() local fullmsg = "error: "..string.match(err, ": (.+)").."\n"..debug.traceback()
gui.alert(fullmsg, function()
if world.is_open() then if hud then
__vc_app.close_world() gui.alert(fullmsg, function()
else if world.is_open() then
__vc_app.reset_content() __vc_app.close_world()
menu:reset() else
menu.page = "main" __vc_app.reset_content()
end menu:reset()
end) menu.page = "main"
end
end)
end
return fullmsg return fullmsg
end) end)
if not status then if not status then