Add API to cancel async jobs (#14602)

* Implement API to cancel async jobs

Co-authored-by: sfan5 <sfan5@live.de>

* update AsyncJob:cancel documentation from review

* Use IPC to unblock async

* review

* review async unblocking

* review

* Apply suggestions from code review

Co-authored-by: sfan5 <sfan5@live.de>

* minor licensing

---------

Co-authored-by: y5nw <y5nw@protonmail.com>
Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
y5nw
2025-08-26 12:40:31 +02:00
committed by GitHub
parent 7cbe62fe7b
commit f390137d6e
12 changed files with 229 additions and 78 deletions

View File

@@ -9,6 +9,7 @@
#include "filesys.h"
#include "cpp_api/s_internal.h"
#include "lua_api/l_areastore.h"
#include "lua_api/l_async.h"
#include "lua_api/l_auth.h"
#include "lua_api/l_base.h"
#include "lua_api/l_craft.h"
@@ -39,7 +40,7 @@ extern "C" {
ServerScripting::ServerScripting(Server* server):
ScriptApiBase(ScriptingType::Server),
asyncEngine(server)
ScriptApiAsync(server)
{
setGameDef(server);
@@ -118,18 +119,6 @@ void ServerScripting::initAsync()
asyncEngine.initialize(0);
}
void ServerScripting::stepAsync()
{
asyncEngine.step(getStack());
}
u32 ServerScripting::queueAsync(std::string &&serialized_func,
PackedValue *param, const std::string &mod_origin)
{
return asyncEngine.queueAsyncJob(std::move(serialized_func),
param, mod_origin);
}
void ServerScripting::InitializeModApi(lua_State *L, int top)
{
// Register reference classes (userdata)
@@ -153,6 +142,7 @@ void ServerScripting::InitializeModApi(lua_State *L, int top)
ModChannelRef::Register(L);
// Initialize mod api modules
ModApiAsync::Initialize(L, top);
ModApiAuth::Initialize(L, top);
ModApiCraft::Initialize(L, top);
ModApiEnv::Initialize(L, top);