Skip to content

Commit ed25887

Browse files
committed
Fix tasks not being removed and change actor select to round robin
1 parent db965f7 commit ed25887

5 files changed

Lines changed: 12 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Read more about Parallel Luau here: [Parallel Luau](https://create.roblox.com/do
1313
2. Add the dependency to your project's `wally.toml` file
1414
```toml
1515
[dependencies]
16-
Parallel = "dig/parallel@1.0.4"
16+
Parallel = "dig/parallel@1.0.5"
1717
```
1818
3. Run `wally install`
1919

src/ClientActor/Worker.client.luau

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ actor:BindToMessage("Parallel:SubmitTask", function(uuid: string, ...: any?)
2525
-- PARALLEL: Switch to parallel thread
2626
task.desynchronize()
2727
bindableEvent:Fire(uuid, preparedRunnable(table.unpack(args)))
28+
tasks[uuid] = nil
2829
end)
2930
end)
3031

src/ServerActor/Worker.server.luau

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ actor:BindToMessage("Parallel:SubmitTask", function(uuid: string, ...: any?)
2525
-- PARALLEL: Switch to parallel thread
2626
task.desynchronize()
2727
bindableEvent:Fire(uuid, preparedRunnable(table.unpack(args)))
28+
tasks[uuid] = nil
2829
end)
2930
end)
3031

src/init.luau

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function Parallel.of(runnable: ModuleScript): PreparedParallel
8383
_actors = {} :: { Actor },
8484
_actorState = {} :: ActorStateMap,
8585
_results = {} :: { [string]: table },
86+
_actorIndex = 1,
8687

8788
_connection = nil,
8889
_destroyed = false,
@@ -111,6 +112,7 @@ function Parallel:withActors(actorCount: number): PreparedParallel
111112
assert(type(actorCount) == "number", "Actor count must be a number")
112113
assert(actorCount > 0, "Actor count must be greater than 0")
113114
self._actorCount = actorCount
115+
self._actorIndex = math.min(self._actorIndex, actorCount)
114116
self:_createActors()
115117
return self
116118
end
@@ -184,19 +186,14 @@ end
184186

185187
function Parallel:_findActor(): Actor
186188
assert(#self._actors > 0, "No actors")
187-
local minActor = self._actors[1]
188-
local min = self._actorState[minActor].count
189-
190-
for i = 2, #self._actors do
191-
local actor = self._actors[i]
192-
local count = self._actorState[actor].count
193-
if count < min then
194-
min = count
195-
minActor = actor
196-
end
189+
local actor = self._actors[self._actorIndex]
190+
191+
self._actorIndex += 1
192+
if self._actorIndex > #self._actors then
193+
self._actorIndex = 1
197194
end
198195

199-
return minActor
196+
return actor
200197
end
201198

202199
function Parallel:_createActors()

wally.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "dig/parallel"
33
description = "Parallel execution library for Roblox lua"
4-
version = "1.0.4"
4+
version = "1.0.5"
55
license = "MIT"
66
registry = "https://github.com/UpliftGames/wally-index"
77
realm = "shared"

0 commit comments

Comments
 (0)