|
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | 13 | @available(FoundationPreview 6.2, *) |
14 | | -// ProgressReporter.Progress |
15 | | -extension ProgressReporter { |
16 | | - /// ProgressReporter.Progress is a nested ~Copyable struct used to establish parent-child relationship between two instances of ProgressReporter. |
17 | | - /// |
18 | | - /// ProgressReporter.Progress is returned from a call to `assign(count:)` by a parent ProgressReporter. |
19 | | - /// A child ProgressReporter is then returned by calling`reporter(totalCount:)` on a ProgressReporter.Progress. |
20 | | - public struct Progress: ~Copyable, Sendable { |
21 | | - internal var parent: ProgressReporter |
22 | | - internal var portionOfParent: Int |
23 | | - internal var isInitializedToProgressReporter: Bool |
| 14 | +/// Subprogress is a nested ~Copyable struct used to establish parent-child relationship between two instances of ProgressReporter. |
| 15 | +/// |
| 16 | +/// Subprogress is returned from a call to `subprogress(assigningCount:)` by a parent ProgressReporter. |
| 17 | +/// A child ProgressReporter is then returned by calling`reporter(totalCount:)` on a Subprogress. |
| 18 | +public struct Subprogress: ~Copyable, Sendable { |
| 19 | + internal var parent: ProgressReporter |
| 20 | + internal var portionOfParent: Int |
| 21 | + internal var isInitializedToProgressReporter: Bool |
| 22 | + |
| 23 | + // Interop variables for Progress - ProgressReporter Interop |
| 24 | + internal var interopWithProgressParent: Bool = false |
| 25 | + // To be kept alive in ProgressReporter |
| 26 | + internal var observation: (any Sendable)? |
| 27 | + internal var ghostReporter: ProgressReporter? |
| 28 | + |
| 29 | + internal init(parent: ProgressReporter, portionOfParent: Int) { |
| 30 | + self.parent = parent |
| 31 | + self.portionOfParent = portionOfParent |
| 32 | + self.isInitializedToProgressReporter = false |
| 33 | + } |
| 34 | + |
| 35 | + /// Instantiates a ProgressReporter which is a child to the parent from which `self` is returned. |
| 36 | + /// - Parameter totalCount: Total count of returned child `ProgressReporter` instance. |
| 37 | + /// - Returns: A `ProgressReporter` instance. |
| 38 | + public consuming func reporter(totalCount: Int?) -> ProgressReporter { |
| 39 | + isInitializedToProgressReporter = true |
24 | 40 |
|
25 | | - // Interop variables for Progress - ProgressReporter Interop |
26 | | - internal var interopWithProgressParent: Bool = false |
27 | | - // To be kept alive in ProgressReporter |
28 | | - internal var observation: (any Sendable)? |
29 | | - internal var ghostReporter: ProgressReporter? |
30 | | - |
31 | | - internal init(parent: ProgressReporter, portionOfParent: Int) { |
32 | | - self.parent = parent |
33 | | - self.portionOfParent = portionOfParent |
34 | | - self.isInitializedToProgressReporter = false |
35 | | - } |
| 41 | + let childReporter = ProgressReporter(total: totalCount, parent: parent, portionOfParent: portionOfParent, ghostReporter: ghostReporter, interopObservation: observation) |
36 | 42 |
|
37 | | - /// Instantiates a ProgressReporter which is a child to the parent from which `self` is returned. |
38 | | - /// - Parameter totalCount: Total count of returned child `ProgressReporter` instance. |
39 | | - /// - Returns: A `ProgressReporter` instance. |
40 | | - public consuming func reporter(totalCount: Int?) -> ProgressReporter { |
41 | | - isInitializedToProgressReporter = true |
42 | | - |
43 | | - let childReporter = ProgressReporter(total: totalCount, parent: parent, portionOfParent: portionOfParent, ghostReporter: ghostReporter, interopObservation: observation) |
44 | | - |
45 | | - if interopWithProgressParent { |
46 | | - // Set interop child of ghost reporter so ghost reporter reads from here |
47 | | - ghostReporter?.setInteropChild(interopChild: childReporter) |
48 | | - } else { |
49 | | - // Add child to parent's _children list |
50 | | - parent.addToChildren(childReporter: childReporter) |
51 | | - } |
52 | | - |
53 | | - return childReporter |
| 43 | + if interopWithProgressParent { |
| 44 | + // Set interop child of ghost reporter so ghost reporter reads from here |
| 45 | + ghostReporter?.setInteropChild(interopChild: childReporter) |
| 46 | + } else { |
| 47 | + // Add child to parent's _children list |
| 48 | + parent.addToChildren(childReporter: childReporter) |
54 | 49 | } |
| 50 | + |
| 51 | + return childReporter |
55 | 52 | } |
56 | 53 | } |
| 54 | + |
0 commit comments