Execute HTTP callbacks on main state not a thread

This commit is contained in:
Mm2PL 2024-10-19 20:39:49 +02:00
parent cd59ca1a8e
commit 30c7618fe5
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9

View file

@ -128,11 +128,7 @@ void HTTPRequest::execute(sol::this_state L)
return; return;
} }
lua::StackGuard guard(L); lua::StackGuard guard(L);
sol::state_view mainState(L); (*self->cbSuccess)(HTTPResponse(res));
sol::thread thread = sol::thread::create(mainState);
sol::state_view threadstate = thread.state();
sol::protected_function cb(threadstate, *self->cbSuccess);
cb(HTTPResponse(res));
self->cbSuccess = std::nullopt; self->cbSuccess = std::nullopt;
}) })
.onError([L, hack](const NetworkResult &res) { .onError([L, hack](const NetworkResult &res) {
@ -146,11 +142,7 @@ void HTTPRequest::execute(sol::this_state L)
return; return;
} }
lua::StackGuard guard(L); lua::StackGuard guard(L);
sol::state_view mainState(L); (*self->cbError)(HTTPResponse(res));
sol::thread thread = sol::thread::create(mainState);
sol::state_view threadstate = thread.state();
sol::protected_function cb(threadstate, *self->cbError);
cb(HTTPResponse(res));
self->cbError = std::nullopt; self->cbError = std::nullopt;
}) })
.finally([L, hack]() { .finally([L, hack]() {
@ -177,11 +169,7 @@ void HTTPRequest::execute(sol::this_state L)
return; return;
} }
lua::StackGuard guard(L); lua::StackGuard guard(L);
sol::state_view mainState(L); (*self->cbFinally)();
sol::thread thread = sol::thread::create(mainState);
sol::state_view threadstate = thread.state();
sol::protected_function cb(threadstate, *self->cbFinally);
cb();
self->cbFinally = std::nullopt; self->cbFinally = std::nullopt;
}) })
.timeout(this->timeout_) .timeout(this->timeout_)