Skip to content

Commit 0818338

Browse files
committed
Switch to parallel thread when running the runnable func
1 parent 16bb60d commit 0818338

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/Actor/Worker.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ local function add(connection: RBXScriptConnection)
1212
table.insert(connections, connection)
1313
end
1414

15-
add(actor:BindToMessageParallel("Parallel:Init", function(bindable: BindableEvent, runnable: (...any?) -> any?)
15+
add(actor:BindToMessage("Parallel:Init", function(bindable: BindableEvent, runnable: (...any?) -> any?)
1616
assert(not destroyed, "Parallel destroyed")
1717
bindableEvent = bindable
1818
preparedRunnable = runnable
@@ -24,7 +24,7 @@ add(actor:BindToMessageParallel("Parallel:Run", function(...: any?)
2424
preparedRunnable(...)
2525
end))
2626

27-
add(actor:BindToMessageParallel("Parallel:SubmitTask", function(uuid: string, ...: any?)
27+
add(actor:BindToMessage("Parallel:SubmitTask", function(uuid: string, ...: any?)
2828
assert(preparedRunnable, "Parallel not initialized")
2929
assert(not destroyed, "Parallel destroyed")
3030
local args = {...}
@@ -34,11 +34,14 @@ add(actor:BindToMessageParallel("Parallel:SubmitTask", function(uuid: string, ..
3434
tasks[uuid] = nil
3535
end
3636
tasks[uuid] = task.spawn(function()
37+
-- PARALLEL: Switch to parallel thread
38+
task.desynchronize()
39+
3740
bindableEvent:Fire(uuid, preparedRunnable(table.unpack(args)))
3841
end)
3942
end))
4043

41-
add(actor:BindToMessageParallel("Parallel:CancelTask", function(uuid: string)
44+
add(actor:BindToMessage("Parallel:CancelTask", function(uuid: string)
4245
assert(preparedRunnable, "Parallel not initialized")
4346
assert(not destroyed, "Parallel destroyed")
4447
if tasks[uuid] ~= nil then
@@ -47,7 +50,7 @@ add(actor:BindToMessageParallel("Parallel:CancelTask", function(uuid: string)
4750
end
4851
end))
4952

50-
add(actor:BindToMessageParallel("Parallel:Destroy", function()
53+
add(actor:BindToMessage("Parallel:Destroy", function()
5154
assert(preparedRunnable, "Parallel not initialized")
5255
assert(not destroyed, "Parallel destroyed")
5356
destroyed = true

0 commit comments

Comments
 (0)