I was messing with Parallel Luau and was finding it tedious to constantly enter-and-leave desynchronization just to get a few tasks done, and the worker classes I found on the forum were not very ideal for my use-case, so I decided to write my own.
It’s very simple, it just utilizes ConnectParallel
and fires between 2 BindeableEvents to communicate the arguments and results. I didn’t do much intensive testing, but this approach seemed to perform better than simply doing task.desync
and task.sync
.
For example, this is how you would use it.
local newWorker = Worker.new()
-- The Callback runs in Parallel
newWorker:Handle(function(A: number, B: number, C: number)
return A + B + C
end)
-- Yields!
local NewNumber: number = newWorker:DoTask(1, 2, 3)
print(NewNumber)
Ideally you would want to have multiple Workers to get the best results.