@@ -50,7 +50,8 @@ internal import _FoundationCollections
5050 /// This takes into account the fraction completed in its children instances if children are present.
5151 /// If `self` is indeterminate, the value will be 0.0.
5252 public var fractionCompleted : Double {
53- _ $observationRegistrar. access ( self , keyPath: \. fractionCompleted)
53+ _ $observationRegistrar. access ( self , keyPath: \. totalCount)
54+ _ $observationRegistrar. access ( self , keyPath: \. completedCount)
5455 return state. withLock { state in
5556 state. getFractionCompleted ( )
5657 }
@@ -59,7 +60,7 @@ internal import _FoundationCollections
5960 /// The state of initialization of `totalCount`.
6061 /// If `totalCount` is `nil`, the value will be `true`.
6162 public var isIndeterminate : Bool {
62- _ $observationRegistrar. access ( self , keyPath: \. isIndeterminate )
63+ _ $observationRegistrar. access ( self , keyPath: \. totalCount )
6364 return state. withLock { state in
6465 state. getIsIndeterminate ( )
6566 }
@@ -68,7 +69,8 @@ internal import _FoundationCollections
6869 /// The state of completion of work.
6970 /// If `completedCount` >= `totalCount`, the value will be `true`.
7071 public var isFinished : Bool {
71- _ $observationRegistrar. access ( self , keyPath: \. isFinished)
72+ _ $observationRegistrar. access ( self , keyPath: \. totalCount)
73+ _ $observationRegistrar. access ( self , keyPath: \. completedCount)
7274 return state. withLock { state in
7375 state. getIsFinished ( )
7476 }
@@ -178,52 +180,48 @@ internal import _FoundationCollections
178180 /// Increases `completedCount` by `count`.
179181 /// - Parameter count: Units of work.
180182 public func complete( count: Int ) {
181- _ $observationRegistrar. withMutation ( of: self , keyPath: \. fractionCompleted) {
182- _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
183+ _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
184+ let parents : [ ParentState ] ? = state. withLock { state in
185+ guard state. selfFraction. completed != ( state. selfFraction. completed + count) else {
186+ return nil
187+ }
188+
189+ state. complete ( by: count)
190+
191+ return state. parents
192+ }
193+ if let parents = parents {
194+ markSelfDirty ( parents: parents)
195+ }
196+ }
197+ }
198+
199+ public func setCounts( _ counts: ( _ completed: inout Int , _ total: inout Int ? ) -> Void ) {
200+ _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
201+ _ $observationRegistrar. withMutation ( of: self , keyPath: \. totalCount) {
183202 let parents : [ ParentState ] ? = state. withLock { state in
184- guard state. selfFraction. completed != ( state. selfFraction. completed + count) else {
203+ var completed = state. selfFraction. completed
204+ var total = state. selfFraction. total
205+
206+ counts ( & completed, & total)
207+
208+ guard state. selfFraction. completed != completed || state. selfFraction. total != total else {
185209 return nil
186210 }
187211
188- state. complete ( by: count)
212+ state. selfFraction. completed = completed
213+ state. selfFraction. total = total
189214
190215 return state. parents
191216 }
217+
192218 if let parents = parents {
193219 markSelfDirty ( parents: parents)
194220 }
195221 }
196222 }
197223 }
198224
199- public func setCounts( _ counts: ( _ completed: inout Int , _ total: inout Int ? ) -> Void ) {
200- _ $observationRegistrar. withMutation ( of: self , keyPath: \. fractionCompleted) {
201- _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
202- _ $observationRegistrar. withMutation ( of: self , keyPath: \. totalCount) {
203- let parents : [ ParentState ] ? = state. withLock { state in
204- var completed = state. selfFraction. completed
205- var total = state. selfFraction. total
206-
207- counts ( & completed, & total)
208-
209- guard state. selfFraction. completed != completed || state. selfFraction. total != total else {
210- return nil
211- }
212-
213- state. selfFraction. completed = completed
214- state. selfFraction. total = total
215-
216- return state. parents
217- }
218-
219- if let parents = parents {
220- markSelfDirty ( parents: parents)
221- }
222- }
223- }
224- }
225- }
226-
227225 // MARK: Internal Observation Support for Extensions
228226
229227 /// Provides access to the observation registrar for use in extensions.
@@ -242,7 +240,6 @@ internal import _FoundationCollections
242240 internal func getProgressFraction( ) -> ProgressFraction {
243241 return state. withLock { state in
244242 return state. selfFraction
245-
246243 }
247244 }
248245
@@ -263,11 +260,13 @@ internal import _FoundationCollections
263260 }
264261
265262 private func markChildDirty( at position: Int ) {
266- let parents : [ ParentState ] ? = state. withLock { state in
267- state. markChildDirty ( at: position)
268- }
269- if let parents = parents {
270- markSelfDirty ( parents: parents)
263+ _ $observationRegistrar. withMutation ( of: self , keyPath: \. completedCount) {
264+ let parents : [ ParentState ] ? = state. withLock { state in
265+ state. markChildDirty ( at: position)
266+ }
267+ if let parents = parents {
268+ markSelfDirty ( parents: parents)
269+ }
271270 }
272271 }
273272
0 commit comments