๐งฉ Fork Guide
July 25, 2025 ยท View on GitHub
๐ Quick Start Guide for using Forks with LuaDoTheWorld
๐ What You'll Learn
- โ How to run code in a new process (fork)
- โ How to wait for a fork to finish
- โ How to stop a forked process
๐ ๏ธ Prerequisites
- LuaDoTheWorld installed and required in your script
- Unix-like environment (Linux, macOS) for process management
๐ด Fork a Process
Run code in a new process (fork):
local dtw = require("luaDoTheWorld/luaDoTheWorld")
local fork = dtw.newFork(function()
print("executed inside fork")
end)
local one_second = 1000 -- milliseconds
fork.wait(one_second)
print("executed in main process")
โน๏ธ Stop a Forked Process
You can stop (kill) a fork if it is still running:
local dtw = require("luaDoTheWorld/luaDoTheWorld")
local fork = dtw.newFork(function()
while true do
print("executed inside fork")
end
end)
local half_second = 500 -- milliseconds
fork.wait(half_second)
if fork.is_alive() then
fork.kill()
end
print("executed in main process")
๐ Quick Reference
| Function | What it does | Example |
|---|---|---|
dtw.newFork(func) | Create a new forked process | dtw.newFork(function() ... end) |
fork.wait(ms) | Wait for fork to finish (ms) | fork.wait(1000) |
fork.is_alive() | Check if fork is running | fork.is_alive() |
fork.kill() | Stop the forked process | fork.kill() |
๐ Need Help?
- ๐ Check the main SDK documentation
- ๐ Look at other example scripts in the SDK
- ๐ Report issues on our GitHub repository