@@ -124,8 +124,8 @@ internal class _StateMachine<Progress, Value, Error>
124124 self . _lock. lock ( )
125125 defer { self . _lock. unlock ( ) }
126126
127- let ( _ , updated ) = self . state. tryUpdate { $0 == . Running ? ( . Fulfilled, true ) : ( $0 , false ) }
128- if updated {
127+ let newState = self . state. updateIf { $0 == TaskState . Running ? . Fulfilled : nil }
128+ if let _ = newState {
129129 self . value. rawValue = value
130130 self . _finish ( )
131131 }
@@ -137,8 +137,8 @@ internal class _StateMachine<Progress, Value, Error>
137137 defer { self . _lock. unlock ( ) }
138138
139139 let toState = errorInfo. isCancelled ? TaskState . Cancelled : . Rejected
140- let ( _ , updated ) = self . state. tryUpdate { $0 == . Running || $0 == . Paused ? ( toState, true ) : ( $0 , false ) }
141- if updated {
140+ let newState = self . state. updateIf { $0 == TaskState . Running || $0 == . Paused ? toState : nil }
141+ if let _ = newState {
142142 self . errorInfo. rawValue = errorInfo
143143 self . _finish ( )
144144 }
@@ -149,8 +149,8 @@ internal class _StateMachine<Progress, Value, Error>
149149 self . _lock. lock ( )
150150 defer { self . _lock. unlock ( ) }
151151
152- let ( _ , updated ) = self . state. tryUpdate { $0 == . Running ? ( . Paused, true ) : ( $0 , false ) }
153- if updated {
152+ let newState = self . state. updateIf { $0 == TaskState . Running ? . Paused : nil }
153+ if let _ = newState {
154154 self . configuration. pause ? ( )
155155 return true
156156 }
@@ -193,8 +193,8 @@ internal class _StateMachine<Progress, Value, Error>
193193
194194 private func _handleResume( ) -> Bool
195195 {
196- let ( _ , updated ) = self . state. tryUpdate { $0 == . Paused ? ( . Running, true ) : ( $0 , false ) }
197- if updated {
196+ let newState = self . state. updateIf { $0 == TaskState . Paused ? . Running : nil }
197+ if let _ = newState {
198198 self . configuration. resume ? ( )
199199 return true
200200 }
@@ -208,8 +208,8 @@ internal class _StateMachine<Progress, Value, Error>
208208 self . _lock. lock ( )
209209 defer { self . _lock. unlock ( ) }
210210
211- let ( _ , updated ) = self . state. tryUpdate { $0 == . Running || $0 == . Paused ? ( . Cancelled, true ) : ( $0 , false ) }
212- if updated {
211+ let newState = self . state. updateIf { $0 == TaskState . Running || $0 == . Paused ? . Cancelled : nil }
212+ if let _ = newState {
213213 self . errorInfo. rawValue = ErrorInfo ( error: error, isCancelled: true )
214214 self . _finish ( )
215215 return true
0 commit comments