11/// Information about a progressing download.
2- ///
2+ ///
33/// This reports the ``totalOperations`` amount of operations to download, how many of them
44/// have already been downloaded as ``downloadedOperations`` and finally a ``fraction`` indicating
55/// relative progress.
6- ///
6+ ///
77/// To obtain a ``ProgressWithOperations`` instance, either use ``SyncStatusData/downloadProgress``
88/// for global progress or ``SyncDownloadProgress/untilPriority(priority:)``.
9- public protocol ProgressWithOperations {
9+ public protocol ProgressWithOperations : Sendable {
1010 /// How many operations need to be downloaded in total for the current download
1111 /// to complete.
1212 var totalOperations : Int32 { get }
@@ -18,42 +18,42 @@ public protocol ProgressWithOperations {
1818public extension ProgressWithOperations {
1919 /// The relative amount of ``totalOperations`` to items in ``downloadedOperations``, as a
2020 /// number between `0.0` and `1.0` (inclusive).
21- ///
21+ ///
2222 /// When this number reaches `1.0`, all changes have been received from the sync service.
2323 /// Actually applying these changes happens before the ``SyncStatusData/downloadProgress``
2424 /// field is cleared though, so progress can stay at `1.0` for a short while before completing.
2525 var fraction : Float {
26- if ( self . totalOperations == 0 ) {
26+ if totalOperations == 0 {
2727 return 0.0
2828 }
2929
30- return Float . init ( self . downloadedOperations) / Float. init ( self . totalOperations)
30+ return Float ( downloadedOperations) / Float( totalOperations)
3131 }
3232}
3333
3434/// Provides realtime progress on how PowerSync is downloading rows.
35- ///
35+ ///
3636/// This type reports progress by extending ``ProgressWithOperations``, meaning that the
3737/// ``ProgressWithOperations/totalOperations``, ``ProgressWithOperations/downloadedOperations``
3838/// and ``ProgressWithOperations/fraction`` properties are available on this instance.
3939/// Additionally, it's possible to obtain progress towards a specific priority only (instead
4040/// of tracking progress for the entire download) by using ``untilPriority(priority:)``.
41- ///
41+ ///
4242/// The reported progress always reflects the status towards the end of a sync iteration (after
4343/// which a consistent snapshot of all buckets is available locally).
44- ///
44+ ///
4545/// In rare cases (in particular, when a [compacting](https://docs.powersync.com/usage/lifecycle-maintenance/compacting-buckets)
4646/// operation takes place between syncs), it's possible for the returned numbers to be slightly
4747/// inaccurate. For this reason, ``SyncDownloadProgress`` should be seen as an approximation of progress.
4848/// The information returned is good enough to build progress bars, but not exaxt enough to track
4949/// individual download counts.
50- ///
50+ ///
5151/// Also note that data is downloaded in bulk, which means that individual counters are unlikely
5252/// to be updated one-by-one.
5353public protocol SyncDownloadProgress : ProgressWithOperations {
5454 /// Returns download progress towardss all data up until the specified `priority`
5555 /// being received.
56- ///
56+ ///
5757 /// The returned ``ProgressWithOperations`` instance tracks the target amount of operations that
5858 /// need to be downloaded in total and how many of them have already been received.
5959 func untilPriority( priority: BucketPriority ) -> ProgressWithOperations
0 commit comments