https://github.com/minetest/minetest/issues/2856
I've come across a considerable limitation while working on one of my mods, which might affect many mods that use delays to schedule important tasks on the server.
I have a mod which schedules a Lua function to execute after several seconds, by putting it in a minetest.after(#) function. It's essential that the delayed functions are eventually ran, as their effect is permanent on the server and there are supposed to be no gaps. However there is no way to prevent the server from shutting down before a minetest.after function gets to finish. Further more, if the server crashes before the function executes, it will be gone before it ever runs.
I would like to know if a way to work around this problem can be found. Personally, I suggest an additional parameter to the minetest.after function, which (when true) marks the call as persistent. If a persistent minetest.after function exists, two things will happen:
- The server does not shut down before the function runs. If someone issues a shutdown command, the server will remain in "shutting down" state until the delayed function finished executing. In addition to this, or alternatively to this:
- When initialized, the function should be stored in a suspended state in the world directory (possibly in a special database) from which it's removed once it executes. If the server crashes before the function runs, the function is retrieved from here once the server is back up, and put back into the queue using the best possible estimation of when the server crashed to know how much time it had left. minetest.after functions using this should of course not contain references to anything that changes between server restarts, just parameters that are constant (like positions)... this is however the mod creator's responsibility.