File tree Expand file tree Collapse file tree 1 file changed +4
-17
lines changed
Samples/Sources/SampleDiningPhilosophers Expand file tree Collapse file tree 1 file changed +4
-17
lines changed Original file line number Diff line number Diff line change 1212//
1313//===----------------------------------------------------------------------===//
1414
15- import AsyncAlgorithms
1615import Distributed
1716import DistributedActors
1817import 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
170157extension Philosopher {
You can’t perform that action at this time.
0 commit comments