aboutsummaryrefslogtreecommitdiff
path: root/builtin/game/async.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
commit21df26984da91143c15587f5a03c98d68c3adc4e (patch)
treeaaa707a628ad331f67890023dffe1b4f60dd01d3 /builtin/game/async.lua
parentb09fc5de5cdb021f43ad32b7e3f50dc75c0bc622 (diff)
parenteabf05758e3ba5f6f4bb1b8d1d1f02179b84e410 (diff)
downloaddragonfireclient-21df26984da91143c15587f5a03c98d68c3adc4e.tar.xz
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'builtin/game/async.lua')
-rw-r--r--builtin/game/async.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/builtin/game/async.lua b/builtin/game/async.lua
new file mode 100644
index 000000000..469f179d7
--- /dev/null
+++ b/builtin/game/async.lua
@@ -0,0 +1,22 @@
+
+core.async_jobs = {}
+
+function core.async_event_handler(jobid, retval)
+ local callback = core.async_jobs[jobid]
+ assert(type(callback) == "function")
+ callback(unpack(retval, 1, retval.n))
+ core.async_jobs[jobid] = nil
+end
+
+function core.handle_async(func, callback, ...)
+ assert(type(func) == "function" and type(callback) == "function",
+ "Invalid minetest.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
+
+ return true
+end
+