1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-05 18:41:05 +00:00

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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 229 additions and 78 deletions

View file

@ -8,15 +8,24 @@ function core.async_event_handler(jobid, retval)
core.async_jobs[jobid] = nil
end
local job_metatable = {__index = {}}
function job_metatable.__index:cancel()
local cancelled = core.cancel_async_callback(self.id)
if cancelled then
core.async_jobs[self.id] = nil
end
return cancelled
end
function core.handle_async(func, callback, ...)
assert(type(func) == "function" and type(callback) == "function",
"Invalid core.handle_async invocation")
local args = {n = select("#", ...), ...}
local mod_origin = core.get_last_run_mod()
local jobid = core.do_async_callback(func, args, mod_origin)
core.async_jobs[jobid] = callback
local id = core.do_async_callback(func, args, mod_origin)
core.async_jobs[id] = callback
return true
return setmetatable({id = id}, job_metatable)
end