Skip to content

[Proposal] Update ProgressManager Proposal #1335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
82c0eba
ProgressReporter proposal
chloe-yeo Feb 25, 2025
f3e5fde
reword future directions section + fix typo
chloe-yeo Feb 26, 2025
6c98f1d
fix spacing
chloe-yeo Feb 26, 2025
4b15850
refactor LocalizedDescriptionOptions
chloe-yeo Feb 27, 2025
3e59ff1
edit future directions
chloe-yeo Feb 27, 2025
5ed834e
update ProgressReporter Pitch to V2
chloe-yeo Apr 3, 2025
21dffe9
update proposal to latest version
chloe-yeo Apr 4, 2025
93b855d
fix spacing
chloe-yeo Apr 4, 2025
720cf0c
v3 updates
chloe-yeo Apr 18, 2025
6384a3a
Merge branch 'swiftlang:main' into proposal/progress-reporter
chloe-yeo Apr 22, 2025
8d6c552
Update review status for SF-0023 to active review
Apr 23, 2025
b7b9c64
Merge branch 'swiftlang:main' into proposal/progress-reporter
chloe-yeo Apr 25, 2025
90e4d54
Merge branch 'swiftlang:main' into proposal/progress-reporter
chloe-yeo May 12, 2025
7d92d2d
Round 2 Pitch
chloe-yeo May 21, 2025
8aa6815
Merge branch 'swiftlang:main' into proposal/progress-reporter
chloe-yeo May 21, 2025
db9c100
fix typo
chloe-yeo May 28, 2025
44de6ee
update proposal to v5
chloe-yeo Jun 2, 2025
8293405
add code documentation
chloe-yeo Jun 3, 2025
4fab79b
Update status for SF-0023 to 2nd Review
iCharlesHu Jun 3, 2025
082a48d
Update 0023-progress-reporter.md
chloe-yeo Jun 4, 2025
b489c17
Merge branch 'main' into proposal/progress-reporter
chloe-yeo Jun 4, 2025
b454399
update name + add total and values to ProgressReporter
chloe-yeo Jun 5, 2025
729918f
Merge branch 'swiftlang:main' into proposal/progress-reporter
chloe-yeo Jun 11, 2025
122dd93
update proposal with minor updates
chloe-yeo Jun 11, 2025
2275867
expand future directions
chloe-yeo Jun 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions Proposals/0023-progress-reporter.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `ProgressReporter`: Progress Reporting in Swift Concurrency
# `ProgressManager`: Progress Reporting in Swift Concurrency

* Proposal: SF-0023
* Author(s): [Chloe Yeo](https://github.com/chloe-yeo)
Expand Down Expand Up @@ -33,6 +33,9 @@
- Moving `FormatStyle` to separate future proposal
* **v5** Minor Updates:
- Renamed `manager(totalCount:)` to `start(totalCount)`
- Changed the return type of `values(of:)` to be an array of non-optional values
- Clarify cycle-detection behavior in `assign(count:to:)` at runtime
- Expanded Future Directions
- Expanded Alternatives Considered

## Table of Contents
Expand Down Expand Up @@ -153,12 +156,12 @@ Another recommended usage pattern of `Progress`, which involves the `ProgressRep

### `ProgressManager` API

We propose introducing a new progress reporting type called `ProgressManager`. `ProgressManager` is used to report progress.
We propose introducing a new progress reporting type called `ProgressManager`. `ProgressManager` is used to manage the composition of progress by either assigning it, or completing it.

In order to compose progress into trees, we also introduce two more types:

1. `Subprogress`: A `~Copyable` type, used when a `ProgressManager` wishes to assign a portion of its total progress to an `async` function.
2. `ProgressReporter`: A class used to report progress to interested observers. This includes one or more other `ProgressManager`s, which may incorporate those updates into their own progress.
2. `ProgressReporter`: A class used to report progress of `ProgressManager` to interested observers. This includes one or more other `ProgressManager`s, which may incorporate those updates into their own progress.

```mermaid
block-beta
Expand Down Expand Up @@ -516,6 +519,8 @@ overall.addChild(subprogressThree, withPendingUnitCount: 1)

/// Adds a `ProgressReporter` as a child, with its progress representing a portion of `self`'s progress.
///
/// If a cycle is detected, this will cause a crash at runtime.
///
/// - Parameters:
/// - output: A `ProgressReporter` instance.
/// - count: The portion of `totalCount` to be delegated to the `ProgressReporter`.
Expand All @@ -534,7 +539,7 @@ overall.addChild(subprogressThree, withPendingUnitCount: 1)
///
/// - Parameter property: Type of property.
/// - Returns: Array of values for property.
public func values<P: ProgressManager.Property>(of property: P.Type) -> [P.Value?]
public func values<P: ProgressManager.Property>(of property: P.Type) -> [P.Value]

/// Returns the aggregated result of values where type of property is `AdditiveArithmetic`.
/// All values are added together.
Expand Down Expand Up @@ -601,6 +606,20 @@ public struct Subprogress: ~Copyable, Sendable {
public func withProperties<T, E: Error>(
_ closure: (sending ProgressManager.Values) throws(E) -> sending T
) throws(E) -> T

/// Returns an array of values for specified property in subtree.
///
/// - Parameter property: Type of property.
/// - Returns: Array of values for property.
public func values<P: ProgressManager.Property>(of property: P.Type) -> [P.Value]

/// Returns the aggregated result of values where type of property is `AdditiveArithmetic`.
/// All values are added together.
///
/// - Parameters:
/// - property: Type of property.
/// - values: Sum of values.
public func total<P: ProgressManager.Property>(of property: P.Type) -> P.Value where P.Value : AdditiveArithmetic
}
```

Expand Down Expand Up @@ -780,6 +799,9 @@ To further safeguard developers from making mistakes of over-assigning or under-
### Support for Non-Integer Formats of Progress Updates
To handle progress values from other sources that provide progress updates as non-integer formats such as `Double`, we can introduce a way for `ProgressManager` to either be instantiated with non-integer formats, or a peer instance of `ProgressManager` that works with `ProgressManager` to compose a progress graph.

### Support for Decomposition of Progress / Display of Hierarchy of Progress Subtree
If there happens to be greater demand of a functionality to either decompose a `ProgressManager` or `ProgressReporter` into its constituents, or to display the hierarchy of the subtree with a `ProgressManager` or `ProgressReporter` at its root, we can introduce additive changes to this API.

## Alternatives considered

### Alternative Names
Expand Down