mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-08-22 15:48:56 +00:00
[common] remove DetachedTasks object usage (#4096)
this was only ever used for announce room json on one single instance this object is pretty much a danger to society and shouldnt exist, especially since its: a) a singleton b) spawns objects out of thin air c) doesn't respect RAII and can outlive its parent objects (big no no) generally we shouldnt endorse objects like these in the future, but alas, it existed, now it has to begone additionally there is a similar object in KWorkerTaskManager but it's not as egregious as this one. check that this didnt break the usual announce room json logic Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4096 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: MaranBr <maranbr@eden-emu.dev>
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <future>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "common/detached_tasks.h"
|
||||
#include "common/logging.h"
|
||||
#include "web_service/announce_room_json.h"
|
||||
#include "web_service/web_backend.h"
|
||||
@@ -136,13 +135,14 @@ AnnounceMultiplayerRoom::RoomList RoomJson::GetRoomList() {
|
||||
void RoomJson::Delete() {
|
||||
if (room_id.empty()) {
|
||||
LOG_ERROR(WebService, "Room must be registered to be deleted");
|
||||
return;
|
||||
} else {
|
||||
// This jthread won't be destroyed until after the dtor has been ran
|
||||
// Once the thread finishes it will stay resident on the vector -- destroyed and freed by dtor()
|
||||
// this is still valid while in dtor, so... yeah
|
||||
detached_tasks.emplace_back([this](std::stop_token stop_token) {
|
||||
client.DeleteJson(fmt::format("/lobby/{}", room_id), "", false);
|
||||
});
|
||||
}
|
||||
Common::DetachedTasks::AddTask([host_{this->host}, username_{this->username},
|
||||
token_{this->token}, room_id_{this->room_id}]() {
|
||||
// create a new client here because the this->client might be destroyed.
|
||||
Client{host_, username_, token_}.DeleteJson(fmt::format("/lobby/{}", room_id_), "", false);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace WebService
|
||||
|
||||
Reference in New Issue
Block a user