Skip to content

Commit 0c9e0a3

Browse files
committed
Moved size to be function back for now
1 parent 265f82f commit 0c9e0a3

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Sources/DistributedCluster/Pattern/WorkerPool.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public distributed actor WorkerPool<Worker: DistributedWorker>: DistributedWorke
122122
level: self.logLevel,
123123
"Incoming work, selecting worker",
124124
metadata: [
125-
"workers/count": "\(self.size)",
125+
"workers/count": "\(self.size())",
126126
"worker/item": "\(work)",
127127
]
128128
)
@@ -132,13 +132,14 @@ public distributed actor WorkerPool<Worker: DistributedWorker>: DistributedWorke
132132
"Selected worker, submitting [\(work)] to [\(worker)]",
133133
metadata: [
134134
"worker": "\(worker.id)",
135-
"workers/count": "\(self.size)",
135+
"workers/count": "\(self.size())",
136136
]
137137
)
138138
return try await worker.submit(work: work)
139139
}
140140

141-
distributed var size: Int {
141+
// FIXME: there is an issue in latest Swift (6.2 nightlies) with Cxx interop, change back to computed properties when fixed.
142+
internal distributed func size() -> Int {
142143
self.workers.count
143144
}
144145

@@ -198,11 +199,11 @@ public distributed actor WorkerPool<Worker: DistributedWorker>: DistributedWorke
198199
case .random:
199200
return self.workers.shuffled().first
200201
case .simpleRoundRobin:
201-
if self.roundRobinPos >= self.size {
202+
if self.roundRobinPos >= self.size() {
202203
self.roundRobinPos = 0 // loop around from zero
203204
}
204205
let selected = self.workers[self.roundRobinPos]
205-
self.roundRobinPos = self.workers.index(after: self.roundRobinPos) % self.size
206+
self.roundRobinPos = self.workers.index(after: self.roundRobinPos) % self.size()
206207
return selected
207208
}
208209
}

Tests/DistributedClusterTests/Pattern/WorkerPoolTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class WorkerPoolTests: SingleClusterSystemXCTestCase {
4646
let finished = expectation(description: "all workers available")
4747
Task {
4848
while true {
49-
if try await workers.size == workerProbes.count {
49+
if try await workers.size() == workerProbes.count {
5050
break
5151
}
5252
try await Task.sleep(nanoseconds: 100_000_000)
@@ -93,7 +93,7 @@ final class WorkerPoolTests: SingleClusterSystemXCTestCase {
9393
let finished = expectation(description: "all workers available")
9494
Task {
9595
while true {
96-
if try await workers.size == workerProbes.count {
96+
if try await workers.size() == workerProbes.count {
9797
break
9898
}
9999
try await Task.sleep(nanoseconds: 100_000_000)
@@ -276,7 +276,7 @@ final class WorkerPoolTests: SingleClusterSystemXCTestCase {
276276
let finished = expectation(description: "all workers available")
277277
Task {
278278
while true {
279-
if try await workers.size == workerProbes.count {
279+
if try await workers.size() == workerProbes.count {
280280
break
281281
}
282282
try await Task.sleep(nanoseconds: 100_000_000)

0 commit comments

Comments
 (0)