Skip to content

Commit 0d8ca55

Browse files
committed
Misc API improvements
1 parent c5c9ce8 commit 0d8ca55

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

packages/powersync_core/lib/src/sync/connection_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ final class _SyncStreamSubscriptionHandle implements SyncStreamSubscription {
372372
Map<String, Object?>? get parameters => _source.parameters;
373373

374374
@override
375-
Future<void> unsubscribe() async {
375+
void unsubscribe() async {
376376
_finalizer.detach(this);
377377
_source.decrementRefCount();
378378
}

packages/powersync_core/lib/src/sync/stream.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ abstract interface class SyncStreamSubscription
7777
/// this stream subscription.
7878
Future<void> waitForFirstSync();
7979

80-
/// Removes this stream subscription from the database, if it has been
81-
/// subscribed to explicitly.
80+
/// Removes this subscription.
8281
///
83-
/// The subscription may still be included for a while, until the client
84-
/// reconnects and receives new snapshots from the sync service.
85-
Future<void> unsubscribe();
82+
/// Once all [SyncStreamSubscription]s for a [SyncStream] have been
83+
/// unsubscribed, the `ttl` for that stream starts running. When it expires
84+
/// without subscribing again, the stream will be evicted.
85+
void unsubscribe();
8686
}
8787

8888
/// An `ActiveStreamSubscription` as part of the sync status in Rust.

packages/powersync_core/lib/src/sync/sync_status.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'dart:math';
22

33
import 'package:collection/collection.dart';
44
import 'package:meta/meta.dart';
5-
import '../database/powersync_database.dart';
65

76
import 'bucket_storage.dart';
87
import 'protocol.dart';
@@ -120,10 +119,8 @@ final class SyncStatus {
120119

121120
/// All sync streams currently being tracked in this subscription.
122121
///
123-
/// This returns null when the sync stream is currently being opened and we
124-
/// don't have reliable information about all included streams yet (in that
125-
/// state, [PowerSyncDatabase.subscribedStreams] can still be used to
126-
/// resolve known subscriptions locally).
122+
/// This returns null when the database is currently being opened and we
123+
/// don't have reliable information about all included streams yet.
127124
Iterable<SyncStreamStatus>? get activeSubscriptions {
128125
return _internalSubscriptions?.map((subscription) {
129126
return SyncStreamStatus._(subscription, downloadProgress);
@@ -221,7 +218,6 @@ final class SyncStreamStatus {
221218

222219
SyncSubscriptionDescription get subscription => _internal;
223220
StreamPriority get priority => _internal.priority;
224-
bool get isDefault => _internal.isDefault;
225221

226222
SyncStreamStatus._(this._internal, SyncDownloadProgress? progress)
227223
: progress = progress?._internal._forStream(_internal);

packages/powersync_core/test/sync/stream_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ void main() {
175175
subscription: isSyncSubscription(
176176
name: 'default_stream',
177177
parameters: null,
178+
isDefault: true,
178179
),
179-
isDefault: true,
180180
),
181181
],
182182
),
@@ -207,7 +207,7 @@ void main() {
207207

208208
// Given that the subscription has a TTL, dropping the handle should not
209209
// re-subscribe.
210-
await subscription.unsubscribe();
210+
subscription.unsubscribe();
211211
await pumpEventQueue();
212212
expect(syncService.controller.hasListener, isTrue);
213213
});

packages/powersync_core/test/sync/utils.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,30 @@ TypeMatcher<ProgressWithOperations> progress(int completed, int total) {
5858
TypeMatcher<SyncStreamStatus> isStreamStatus({
5959
required Object? subscription,
6060
Object? progress,
61-
Object? isDefault,
6261
}) {
6362
var matcher = isA<SyncStreamStatus>()
6463
.having((e) => e.subscription, 'subscription', subscription);
6564
if (progress case final progress?) {
6665
matcher = matcher.having((e) => e.progress, 'progress', progress);
6766
}
68-
if (isDefault case final isDefault?) {
69-
matcher = matcher.having((e) => e.isDefault, 'isDefault', isDefault);
70-
}
7167

7268
return matcher;
7369
}
7470

7571
TypeMatcher<SyncSubscriptionDescription> isSyncSubscription({
7672
required Object name,
7773
required Object? parameters,
74+
bool? isDefault,
7875
}) {
79-
return isA<SyncSubscriptionDescription>()
76+
var matcher = isA<SyncSubscriptionDescription>()
8077
.having((e) => e.name, 'name', name)
8178
.having((e) => e.parameters, 'parameters', parameters);
79+
80+
if (isDefault != null) {
81+
matcher = matcher.having((e) => e.isDefault, 'isDefault', isDefault);
82+
}
83+
84+
return matcher;
8285
}
8386

8487
BucketChecksum checksum(

0 commit comments

Comments
 (0)