Threader is Easy to Use, Promise Based and uses Send Data Get Data structure. Threader was made to make working with Actors easier and overall tie everything together. Once Threader had dispatched the work and all the threads had finished, it will return all of the data that the threads had returned.
Creating a Threader class is very simple. The first argument is always how many threads are there initially and the last one is the ThreadWorker itself.
local Threader = require(game:GetService("ReplicatedStorage").Threader)
local myThreader = Threader.new(5, PATH.TO.WORKER.MODULE)A ThreadWorker is a ModuleScript that is used to process the data in all of the threads
once Threader:Dispatch() was called.
local myThreadWorker = Threader.ThreadWorker.new()
function myThreadWorker:OnDispatch(data)
return data
end
function myThreadWorker:OnCancel()
print("Cancelled!")
end
return myThreadWorkerGetting the data back from all of the threads is very simple! Since Threader is Promise based after calling Threader:Dispatch() a Promise will be returned that will resolve once all of the threads had completed or gets rejected if any error occurs!
local myThreader = Threader.new(5, script.MyThreadWorkerModule)
myThreader:Dispatch(table.create(1000, 1)):andThen(function(results)
print(results)
end)local MyThreadWorker = Threader.ThreadWorker.new()
function MyThreadWorker:OnDispatch(data)
local sum = 0
for _, num in data do
sum += num
end
return sum
end
return MyThreadWorker