Skip to content

Commit c969aa3

Browse files
committed
add access and withMutation calls for additional properties summary
1 parent d7ce17b commit c969aa3

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

Sources/FoundationEssentials/ProgressManager/ProgressManager+Properties+Accessors.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,19 @@ extension ProgressManager {
424424
/// - Returns: An `Int` summary value for the specified property.
425425
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Int, P.Summary == Int {
426426
if property.self == ProgressManager.Properties.TotalFileCount.self {
427-
self.access(keyPath: \.summarySink)
428427
self.access(keyPath: \.totalFileCount)
429-
self.didSet(keyPath: \.summarySink)
428+
self.access(keyPath: \.totalFileCountSummary)
429+
self.didSet(keyPath: \.totalFileCountSummary)
430430
return updatedFileCount(type: .total)
431431
} else if property.self == ProgressManager.Properties.CompletedFileCount.self {
432432
self.access(keyPath: \.completedFileCount)
433+
self.access(keyPath: \.completedFileCountSummary)
434+
self.didSet(keyPath: \.completedFileCountSummary)
433435
return updatedFileCount(type: .completed)
434436
} else {
435437
self.access(keyPath: \.additionalPropertiesSink)
438+
self.access(keyPath: \.additionalPropertiesSummarySink)
439+
self.didSet(keyPath: \.additionalPropertiesSummarySink)
436440
return updatedIntSummary(property: MetatypeWrapper(property))
437441
}
438442
}
@@ -448,12 +452,18 @@ extension ProgressManager {
448452
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == UInt64 {
449453
if property.self == ProgressManager.Properties.TotalByteCount.self {
450454
self.access(keyPath: \.totalByteCount)
455+
self.access(keyPath: \.totalByteCountSummary)
456+
self.didSet(keyPath: \.totalByteCountSummary)
451457
return updatedByteCount(type: .total)
452458
} else if property.self == ProgressManager.Properties.CompletedByteCount.self {
453459
self.access(keyPath: \.completedByteCount)
460+
self.access(keyPath: \.completedByteCountSummary)
461+
self.didSet(keyPath: \.completedByteCountSummary)
454462
return updatedByteCount(type: .completed)
455463
} else {
456464
self.access(keyPath: \.additionalPropertiesSink)
465+
self.access(keyPath: \.additionalPropertiesSummarySink)
466+
self.didSet(keyPath: \.additionalPropertiesSummarySink)
457467
return updatedUInt64Summary(property: MetatypeWrapper(property))
458468
}
459469
}
@@ -468,6 +478,8 @@ extension ProgressManager {
468478
/// - Returns: A `Double` summary value for the specified property.
469479
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Double, P.Summary == Double {
470480
self.access(keyPath: \.additionalPropertiesSink)
481+
self.access(keyPath: \.additionalPropertiesSummarySink)
482+
self.didSet(keyPath: \.additionalPropertiesSummarySink)
471483
return updatedDoubleSummary(property: MetatypeWrapper(property))
472484
}
473485

@@ -481,6 +493,8 @@ extension ProgressManager {
481493
/// - Returns: A `[String?]` summary value for the specified property.
482494
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == String?, P.Summary == [String?] {
483495
self.access(keyPath: \.additionalPropertiesSink)
496+
self.access(keyPath: \.additionalPropertiesSummarySink)
497+
self.didSet(keyPath: \.additionalPropertiesSummarySink)
484498
return updatedStringSummary(property: MetatypeWrapper(property))
485499
}
486500

@@ -494,6 +508,8 @@ extension ProgressManager {
494508
/// - Returns: A `[URL?]` summary value for the specified property.
495509
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
496510
self.access(keyPath: \.additionalPropertiesSink)
511+
self.access(keyPath: \.additionalPropertiesSummarySink)
512+
self.didSet(keyPath: \.additionalPropertiesSummarySink)
497513
return updatedURLSummary(property: MetatypeWrapper(property))
498514
}
499515

@@ -508,9 +524,13 @@ extension ProgressManager {
508524
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == [UInt64] {
509525
if property.self == ProgressManager.Properties.Throughput.self {
510526
self.access(keyPath: \.throughput)
527+
self.access(keyPath: \.throughputSummary)
528+
self.didSet(keyPath: \.throughputSummary)
511529
return updatedThroughput()
512530
} else {
513531
self.access(keyPath: \.additionalPropertiesSink)
532+
self.access(keyPath: \.additionalPropertiesSummarySink)
533+
self.didSet(keyPath: \.additionalPropertiesSummarySink)
514534
return updatedUInt64ArraySummary(property: MetatypeWrapper(property))
515535
}
516536
}
@@ -526,9 +546,13 @@ extension ProgressManager {
526546
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Duration, P.Summary == Duration {
527547
if property.self == ProgressManager.Properties.EstimatedTimeRemaining.self {
528548
self.access(keyPath: \.estimatedTimeRemaining)
549+
self.access(keyPath: \.estimatedTimeRemainingSummary)
550+
self.didSet(keyPath: \.estimatedTimeRemainingSummary)
529551
return updatedEstimatedTimeRemaining()
530552
} else {
531553
self.access(keyPath: \.additionalPropertiesSink)
554+
self.access(keyPath: \.additionalPropertiesSummarySink)
555+
self.didSet(keyPath: \.additionalPropertiesSummarySink)
532556
return updatedDurationSummary(property: MetatypeWrapper(property))
533557
}
534558
}

Sources/FoundationEssentials/ProgressManager/ProgressManager+Properties+Helpers.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ extension ProgressManager {
145145
state.getFileCountUpdateInfo(type: type)
146146
}
147147

148-
// for child in updateInfo.dirtyChildren.compactMap({ $0.manager }) {
149-
// child.access(keyPath: \.summarySink)
150-
// }
151-
152148
// Get updated summary for each dirty child
153149
let updatedSummaries = updateInfo.dirtyChildren.map { (index, child) in
154150
State.FileCountUpdate(index: index, updatedSummary: child.updatedFileCount(type: type))
@@ -292,91 +288,103 @@ extension ProgressManager {
292288
}
293289

294290
internal func markChildDirty(property: MetatypeWrapper<Int, Int>, at position: Int) {
291+
self.willSet(keyPath: \.additionalPropertiesSummarySink)
295292
let parents = state.withLock { state in
296293
state.markChildDirty(property: property, at: position)
297294
}
298295
markSelfDirty(property: property, parents: parents)
299296
}
300297

301298
internal func markChildDirty(property: MetatypeWrapper<UInt64, UInt64>, at position: Int) {
299+
self.willSet(keyPath: \.additionalPropertiesSummarySink)
302300
let parents = state.withLock { state in
303301
state.markChildDirty(property: property, at: position)
304302
}
305303
markSelfDirty(property: property, parents: parents)
306304
}
307305

308306
internal func markChildDirty(property: MetatypeWrapper<Double, Double>, at position: Int) {
307+
self.willSet(keyPath: \.additionalPropertiesSummarySink)
309308
let parents = state.withLock { state in
310309
state.markChildDirty(property: property, at: position)
311310
}
312311
markSelfDirty(property: property, parents: parents)
313312
}
314313

315314
internal func markChildDirty(property: MetatypeWrapper<String?, [String?]>, at position: Int) {
315+
self.willSet(keyPath: \.additionalPropertiesSummarySink)
316316
let parents = state.withLock { state in
317317
state.markChildDirty(property: property, at: position)
318318
}
319319
markSelfDirty(property: property, parents: parents)
320320
}
321321

322322
internal func markChildDirty(property: MetatypeWrapper<URL?, [URL?]>, at position: Int) {
323+
self.willSet(keyPath: \.additionalPropertiesSummarySink)
323324
let parents = state.withLock { state in
324325
state.markChildDirty(property: property, at: position)
325326
}
326327
markSelfDirty(property: property, parents: parents)
327328
}
328329

329330
internal func markChildDirty(property: MetatypeWrapper<UInt64, [UInt64]>, at position: Int) {
331+
self.willSet(keyPath: \.additionalPropertiesSummarySink)
330332
let parents = state.withLock { state in
331333
state.markChildDirty(property: property, at: position)
332334
}
333335
markSelfDirty(property: property, parents: parents)
334336
}
335337

336338
internal func markChildDirty(property: MetatypeWrapper<Duration, Duration>, at position: Int) {
339+
self.willSet(keyPath: \.additionalPropertiesSummarySink)
337340
let parents = state.withLock { state in
338341
state.markChildDirty(property: property, at: position)
339342
}
340343
markSelfDirty(property: property, parents: parents)
341344
}
342345

343346
internal func markChildDirty(property: ProgressManager.Properties.TotalFileCount.Type, at position: Int) {
344-
self.willSet(keyPath: \.summarySink)
347+
self.willSet(keyPath: \.totalFileCountSummary)
345348
let parents = state.withLock { state in
346349
state.markChildDirty(property: property, at: position)
347350
}
348351
markSelfDirty(property: property, parents: parents)
349352
}
350353

351354
internal func markChildDirty(property: ProgressManager.Properties.CompletedFileCount.Type, at position: Int) {
355+
self.willSet(keyPath: \.completedFileCountSummary)
352356
let parents = state.withLock { state in
353357
state.markChildDirty(property: property, at: position)
354358
}
355359
markSelfDirty(property: property, parents: parents)
356360
}
357361

358362
internal func markChildDirty(property: ProgressManager.Properties.TotalByteCount.Type, at position: Int) {
363+
self.willSet(keyPath: \.totalByteCountSummary)
359364
let parents = state.withLock { state in
360365
state.markChildDirty(property: property, at: position)
361366
}
362367
markSelfDirty(property: property, parents: parents)
363368
}
364369

365370
internal func markChildDirty(property: ProgressManager.Properties.CompletedByteCount.Type, at position: Int) {
371+
self.willSet(keyPath: \.completedByteCountSummary)
366372
let parents = state.withLock { state in
367373
state.markChildDirty(property: property, at: position)
368374
}
369375
markSelfDirty(property: property, parents: parents)
370376
}
371377

372378
internal func markChildDirty(property: ProgressManager.Properties.Throughput.Type, at position: Int) {
379+
self.willSet(keyPath: \.throughputSummary)
373380
let parents = state.withLock { state in
374381
state.markChildDirty(property: property, at: position)
375382
}
376383
markSelfDirty(property: property, parents: parents)
377384
}
378385

379386
internal func markChildDirty(property: ProgressManager.Properties.EstimatedTimeRemaining.Type, at position: Int) {
387+
self.willSet(keyPath: \.estimatedTimeRemainingSummary)
380388
let parents = state.withLock { state in
381389
state.markChildDirty(property: property, at: position)
382390
}

Sources/FoundationEssentials/ProgressManager/ProgressManager.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ internal import _FoundationCollections
2828

2929
internal let state: Mutex<State>
3030
internal let additionalPropertiesSink: Void
31-
internal let summarySink: Void
31+
internal let additionalPropertiesSummarySink: Void
32+
internal let totalFileCountSummary: Void
33+
internal let completedFileCountSummary: Void
34+
internal let totalByteCountSummary: Void
35+
internal let completedByteCountSummary: Void
36+
internal let throughputSummary: Void
37+
internal let estimatedTimeRemainingSummary: Void
3238

3339
/// The total units of work.
3440
public var totalCount: Int? {

0 commit comments

Comments
 (0)