minetest mod.
Go to file
2019-10-15 11:19:31 -05:00
async.lua Make: foreach take any pair data 2019-10-15 11:19:31 -05:00
init.lua Remove: all extend_api names from repo 2019-05-13 14:22:21 -05:00
LICENSE Initial commit 2018-10-22 13:47:34 -05:00
mod.conf Remove: all extend_api names from repo 2019-05-13 14:22:21 -05:00
README.md Make: foreach take any pair data 2019-10-15 11:19:31 -05:00

async

async mod is a library pack. It adds two new node events and contains async functions.

Usage Async

  1. create a async instance.
async = async.Async()
  1. max time for thread before yielding (maxtime is in milliseconds).
async.maxtime = 200
  1. queue_threads is the amount of active threads when you run function queue_task.
async.queue_threads = 8
  1. iterate from 1 to 50 and log the value i.
async.iterate(1, 50, function(i)
	minetest.log(i)
end, function() minetest.log("Callback") end)
  1. run throught each element in a table.
local array = {"start", "text2", "text3", "text4", "text5", "end"}
async.foreach(pairs(array), function(k, v)
	minetest.log(v)
end, function() minetest.log("Callback") end)
  1. async do while loop.
local c = 50
async.do_while(function() return c > 0 end, function()
	minetest.log(c)
	c = c - 1
end, function() minetest.log("Callback") end)
  1. register a async globalstep. this one spams the chat with the word spam.
async.register_globalstep(function(dtime) 
	minetest.chat_send_all("spam")
end)
  1. chain task runs a group of functions from a table.
async.chain_task({
	function(args)
		args.count = 1
		minetest.log(args.count)
		return args
	end,
	function(args)
		args.count = args.count + 1
		minetest.log(args.count)
		return args
end}, function(args) minetest.log(args.count) end)
  1. adds a single function to the task queue. This is a sort of waiting list.
async.queue_task(function() 
	minetest.log("Hello World!")
end, function(args) minetest.log("callback") end)
  1. Same as queue_task but the task does not go into a queue.
async.single_task(function() 
	minetest.log("Hello World!")
end, function(args) minetest.log("callback") end)