Skip to content

Commit 892a857

Browse files
committed
Update samples per feedback
1 parent f0d11b2 commit 892a857

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

Samples/Sources/SampleDiningPhilosophers/Philosopher.swift

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import AsyncAlgorithms
1615
import Distributed
1716
import DistributedActors
1817
import Logging
@@ -61,11 +60,8 @@ distributed actor Philosopher: CustomStringConvertible {
6160

6261
self.state = .thinking
6362
self.becomeHungryTimerTask = Task {
64-
for await _ in AsyncTimerSequence(interval: .seconds(1), clock: ContinuousClock()) {
65-
await self.attemptToTakeForks()
66-
self.becomeHungryTimerTask?.cancel()
67-
break
68-
}
63+
try await Task.sleep(until: .now + .seconds(1), clock: .continuous)
64+
await self.attemptToTakeForks()
6965
}
7066
self.log.info("\(self.name) is thinking...")
7167
}
@@ -152,19 +148,10 @@ distributed actor Philosopher: CustomStringConvertible {
152148
self.state = .eating
153149
self.log.notice("\(self.name) began eating!")
154150
self.finishEatingTimerTask = Task {
155-
for await _ in AsyncTimerSequence(interval: .seconds(3), clock: ContinuousClock()) {
156-
self.stopEating()
157-
self.finishEatingTimerTask?.cancel()
158-
break
159-
}
151+
try await Task.sleep(until: .now + .seconds(3), clock: .continuous)
152+
self.stopEating()
160153
}
161154
}
162-
163-
deinit {
164-
// FIXME: these are async
165-
// self.becomeHungryTimerTask?.cancel()
166-
// self.finishEatingTimerTask?.cancel()
167-
}
168155
}
169156

170157
extension Philosopher {

0 commit comments

Comments
 (0)