Skip to content

Commit 5aa67da

Browse files
committed
add support for UInt64 and Duration types
1 parent 50038de commit 5aa67da

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

Proposals/0023-progress-manager.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
- Expanded Future Directions
4242
- Expanded Alternatives Considered
4343
* **v6** Minor Updates:
44-
- Changed behavior of API so that additional properties are restricted to either `Int`, `Double`, `String?`, `URL?`, or `UInt64` types instead of `any Sendable` types
44+
- Changed behavior of API so that additional properties are restricted to either `Int`, `Double`, `String?`, `URL?`, `UInt64` or `Duration` types instead of `any Sendable` types
4545
- Added requirements to `ProgressManager.Property` protocol to define summarization and termination (deinit) behavior
4646
- Added overloads for `subscript(dynamicMember:)` in `ProgressManager.Values` to account for currently-allowed types
4747
- Removed `values(of:)` method
@@ -362,10 +362,12 @@ You can define additional properties specific to the operations you are reportin
362362

363363
The currently allowed (Value, Summary) pairs for custom properties are:
364364
- (`Int`, `Int`)
365+
- (`UInt64`, `UInt64`)
365366
- (`Double`, `Double`)
366367
- (`String?`, `[String?]`)
367368
- (`URL?`, `[URL?]`)
368369
- (`UInt64`, `[UInt64]`)
370+
- (`Duration`, `Duration`)
369371

370372
You can declare a custom additional property that has a `String?` `Value` type and `[String?]` `Summary` type as follows:
371373

@@ -587,10 +589,12 @@ public struct Subprogress: ~Copyable, Sendable {
587589

588590
`ProgressManager` contains a protocol `Property` that outlines the requirements for declaring a custom additional property. The currently allowed (Value, Summary) pairs are as follows:
589591
- (`Int`, `Int`)
592+
- (`UInt64`, `UInt64`)
590593
- (`Double`, `Double`)
591594
- (`String?`, `[String?]`)
592595
- (`URL?`, `[URL?]`)
593596
- (`UInt64`, `[UInt64]`)
597+
- (`Duration`, `Duration`)
594598

595599
This list of allowed (Value, Summary) pairs may be expanded in the future. Based on pre-existing use cases of additional properties on `Progress`, we believe that the currently allowed (Value, Summary) pairs should suffice for most use cases.
596600

@@ -871,6 +875,15 @@ extension ProgressManager {
871875
///
872876
/// - Parameter key: A key path to the custom integer property type.
873877
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> Int where P.Value == Int, P.Summary == Int { get set }
878+
879+
/// Gets or sets custom unsigned integer properties.
880+
///
881+
/// This subscript provides read-write access to custom progress properties where both the value
882+
/// and summary types are `UInt64`. If the property has not been set, the getter returns the
883+
/// property's default value.
884+
///
885+
/// - Parameter key: A key path to the custom integer property type.
886+
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> UInt64 where P.Value == UInt64, P.Summary == UInt64 { get set }
874887

875888
/// Gets or sets custom double properties.
876889
///
@@ -908,6 +921,15 @@ extension ProgressManager {
908921
/// - Parameter key: A key path to the custom UInt64 property type.
909922
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> UInt64 where P.Value == UInt64, P.Summary == [UInt64] { get set }
910923

924+
/// Gets or sets custom duration properties.
925+
///
926+
/// This subscript provides read-write access to custom progress properties where both the value
927+
/// and summary types are `Duration`. If the property has not been set, the getter returns the
928+
/// property's default value.
929+
///
930+
/// - Parameter key: A key path to the custom double property type.
931+
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> Duration where P.Value == Duration, P.Summary == Duration { get set }
932+
911933
/// Gets or sets the total file count property.
912934
/// - Parameter key: A key path to the `TotalFileCount` property type.
913935
public subscript(dynamicMember key: KeyPath<ProgressManager.Properties, ProgressManager.Properties.TotalFileCount.Type>) -> Int { get set }
@@ -950,6 +972,16 @@ extension ProgressManager {
950972
/// where both the value and summary types are `Int`.
951973
/// - Returns: An `Int` summary value for the specified property.
952974
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Int, P.Summary == Int
975+
976+
/// Returns a summary for a custom unsigned integer property across the progress subtree.
977+
///
978+
/// This method aggregates the values of a custom integer property from this progress manager
979+
/// and all its children, returning a consolidated summary value.
980+
///
981+
/// - Parameter property: The type of the integer property to summarize. Must be a property
982+
/// where both the value and summary types are `UInt64`.
983+
/// - Returns: An `UInt64` summary value for the specified property.
984+
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == UInt64
953985

954986
/// Returns a summary for a custom double property across the progress subtree.
955987
///
@@ -991,6 +1023,16 @@ extension ProgressManager {
9911023
/// - Returns: A `[UInt64]` summary value for the specified property.
9921024
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == [UInt64]
9931025

1026+
/// Returns a summary for a custom duration property across the progress subtree.
1027+
///
1028+
/// This method aggregates the values of a custom integer property from this progress manager
1029+
/// and all its children, returning a consolidated summary value.
1030+
///
1031+
/// - Parameter property: The type of the integer property to summarize. Must be a property
1032+
/// where both the value and summary types are `Duration`.
1033+
/// - Returns: An `Duration` summary value for the specified property.
1034+
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Duration, P.Summary == Duration
1035+
9941036
/// Returns the total file count across the progress subtree.
9951037
///
9961038
/// This includes the total file count of `ProgressManager`s that are finished.
@@ -1092,6 +1134,16 @@ extension ProgressManager {
10921134
/// where both the value and summary types are `Int`.
10931135
/// - Returns: An `Int` summary value for the specified property.
10941136
public func summary<P: ProgressManager.Property>(of property: P.Type) -> Int where P.Value == Int, P.Summary == Int
1137+
1138+
/// Returns a summary for a custom unsigned integer property across the progress subtree.
1139+
///
1140+
/// This method aggregates the values of a custom integer property from the underlying progress manager
1141+
/// and all its children, returning a consolidated summary value.
1142+
///
1143+
/// - Parameter property: The type of the integer property to summarize. Must be a property
1144+
/// where both the value and summary types are `UInt64`.
1145+
/// - Returns: An `UInt64` summary value for the specified property.
1146+
public func summary<P: ProgressManager.Property>(of property: P.Type) -> UInt64 where P.Value == UInt64, P.Summary == UInt64
10951147

10961148
/// Returns a summary for a custom double property across the progress subtree.
10971149
///
@@ -1134,6 +1186,16 @@ extension ProgressManager {
11341186
/// - Returns: A `[UInt64]` summary value for the specified property.
11351187
public func summary<P: ProgressManager.Property>(of property: P.Type) -> [UInt64] where P.Value == UInt64, P.Summary == [UInt64]
11361188

1189+
/// Returns a summary for a custom duration property across the progress subtree.
1190+
///
1191+
/// This method aggregates the values of a custom integer property from the underlying progress manager
1192+
/// and all its children, returning a consolidated summary value.
1193+
///
1194+
/// - Parameter property: The type of the integer property to summarize. Must be a property
1195+
/// where both the value and summary types are `Duration`.
1196+
/// - Returns: An `Duraton` summary value for the specified property.
1197+
public func summary<P: ProgressManager.Property>(of property: P.Type) -> Duration where P.Value == Duration, P.Summary == Duration
1198+
11371199
/// Returns the total file count across the progress subtree.
11381200
///
11391201
/// This includes the total file count of `ProgressManager`s that are finished.
@@ -1453,7 +1515,7 @@ We previously considered making `totalCount` a settable property on `ProgressMan
14531515
There were discussions about representing indeterminate state in `ProgressManager` alternatively, for example, using enums. However, since `totalCount` is an optional and can be set to `nil` to represent indeterminate state, we think that this is straightforward and sufficient to represent indeterminate state for cases where developers do not know `totalCount` at the start of an operation they want to report progress for. A `ProgressManager` becomes determinate once its `totalCount` is set to an `Int`.
14541516

14551517
### Allow declared custom additional property to be any type that can be casted as `any Sendable`
1456-
We initially allowed the full flexibility of allowing developers to declare `ProgressManager.Property` types to be of any type, including structs. However, we realized that this has a severely negative impact on performance of the API. Thus, for now, we allow developers to only declare `ProgressManager.Property` with only certain `Value` and `Summary` types.
1518+
We initially allowed the full flexibility of allowing developers to declare `ProgressManager.Property` types to be of any type, including structs. However, we realized that this has a severely negative impact on performance of the API. Thus, for now, we allow developers to only declare `ProgressManager.Property` with only certain `Value` and `Summary` types.
14571519

14581520
## Acknowledgements
14591521
Thanks to

0 commit comments

Comments
 (0)