A simple parallel execution library for Roblox lua.
This library uses Roblox actors to run tasks in parallel.
Read more about Parallel Luau here: Parallel Luau
- Install Wally
- Add the dependency to your project's
wally.tomlfile
[dependencies]
Parallel = "dig/parallel@1.0.5"- Run
wally install
- Download the
Parallel.rbxmfile from the latest release - Drag it into your
ReplicatedStoragefolder
This example runs a function that returns "Hello, world!" in a new thread:
localReplicatedStorage=game:GetService("ReplicatedStorage")
localPackages=ReplicatedStorage:WaitForChild("Packages")
-- Require parallel modulelocalParallel=require(Packages.Parallel)
-- Prepare a thread with a runnable module script-- See below for ExampleHelloWorld.lualocalpreparedThread=Parallel.of(script.ExampleHelloWorld)
-- Submit the thread and get the result via promiselocalresult=preparedThread:submit():expect()
print(result) -- Prints "Hello, world!"preparedThread:destroy()ExampleHelloWorld.lua module script:
returnfunction()
return"Hello, world!"endThis example runs spatial query function GetPartBoundsInBox in a new thread and returns the result:
localRunService=game:GetService("RunService")
localReplicatedStorage=game:GetService("ReplicatedStorage")
localPackages=ReplicatedStorage:WaitForChild("Packages")
-- Require parallel modulelocalParallel=require(Packages.Parallel)
-- Prepare a thread with a runnable module script-- See below for SpatialQuery.lualocalpreparedThread=Parallel.of(script.SpatialQuery)
:withName("SpatialQueryWorker")
:withActors(2)
-- Example zone of 200 x 200 x 200localzone=Instance.new("Part")
zone.Name="Zone"zone.Position=Vector3.new(0, 0, 0)
zone.Size=Vector3.new(200, 200, 200)
zone.Anchored=truezone.CanCollide=truezone.Transparency=0.8zone.Parent=workspacewhileRunService:IsRunning() do-- Submit the thread and get the result via promiselocalparts=preparedThread:submit(zone.CFrame, zone.Size):expect()
print(parts) -- Prints array of instances found inside the provided zonetask.wait(1)
endpreparedThread:destroy()SpatialQuery.lua module script:
returnfunction(position: CFrame, size: Vector3)
returnworkspace:GetPartBoundsInBox(position, size)
end