Skip to content

Commit 789629d

Browse files
authored
chore: update core extension to 0.4.11 (#47)
1 parent b71d3b9 commit 789629d

6 files changed

Lines changed: 30 additions & 16 deletions

File tree

PowerSync/PowerSync.Common/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 0.0.11-alpha.1
44

5+
- Updated to the latest version (0.4.11) of the core extension.
56
- `MDSQLiteConnection` now runs query operations on another thread, which stops the caller thread from blocking.
67
- Removed the `RunListener` and `RunListenerAsync` APIs from `IEventStream`. Users are encouraged to use the `Listen` or `ListenAsync` APIs instead (`RunListener` itself was implemented using the `Listen` API).
78
- Changed the `PowerSyncDatabase.Watch` syntax to return an IAsyncEnumerable instead of accepting a callback. This allows users to handle database changes when they are ready instead of us eagerly running the callback as soon as a change is detected.

PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ public PowerSyncDatabase(PowerSyncDatabaseOptions options)
204204
Logger = Logger
205205
});
206206

207-
var syncStreamStatusCts = new CancellationTokenSource();
208-
var _ = Task.Run(() =>
207+
var syncStreamStatusCts = CancellationTokenSource.CreateLinkedTokenSource(masterCts.Token);
208+
var syncStreamStatusListener = syncStreamImplementation.ListenAsync(syncStreamStatusCts.Token);
209+
var _ = Task.Run(async () =>
209210
{
210-
foreach (var update in syncStreamImplementation.Listen(syncStreamStatusCts.Token))
211+
await foreach (var update in syncStreamStatusListener)
211212
{
212213
if (update.StatusChanged != null)
213214
{
@@ -280,36 +281,36 @@ public async Task WaitForFirstSync(PrioritySyncRequest? request = null)
280281
/// <param name="cancellationToken">Optional cancellation token to abort the wait.</param>
281282
public async Task WaitForStatus(Func<SyncStatus, bool> predicate, CancellationToken? cancellationToken = null)
282283
{
284+
var cts = cancellationToken == null
285+
? CancellationTokenSource.CreateLinkedTokenSource(masterCts.Token)
286+
: CancellationTokenSource.CreateLinkedTokenSource(masterCts.Token, cancellationToken.Value);
287+
288+
var statusListener = ListenAsync(cts.Token);
289+
283290
if (predicate(CurrentStatus))
284291
{
292+
cts.Cancel();
285293
return;
286294
}
287295

288296
var tcs = new TaskCompletionSource<bool>();
289-
var cts = CancellationTokenSource.CreateLinkedTokenSource(masterCts.Token);
290297

291298
_ = Task.Run(async () =>
292299
{
293300
try
294301
{
295-
await foreach (var update in ListenAsync(cts.Token))
302+
await foreach (var update in statusListener)
296303
{
297-
if (update.StatusChanged != null && predicate(update.StatusChanged))
304+
if ((update.StatusChanged != null) && predicate(update.StatusChanged))
298305
{
299-
cts.Cancel();
300306
tcs.TrySetResult(true);
307+
cts.Cancel();
301308
}
302309
}
303310
}
304311
catch (OperationCanceledException) { }
305312
});
306313

307-
cancellationToken?.Register(() =>
308-
{
309-
cts.Cancel();
310-
tcs.TrySetCanceled();
311-
});
312-
313314
await tcs.Task;
314315
}
315316

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using FactAttribute = PowerSync.Common.Tests.Utils.FactAttribute;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace PowerSync.Common.Tests.Utils;
2+
3+
[AttributeUsage(AttributeTargets.Method)]
4+
public class FactAttribute : Xunit.FactAttribute
5+
{
6+
public FactAttribute()
7+
{
8+
Timeout = 5000;
9+
}
10+
}

Tests/PowerSync/PowerSync.Common.Tests/Utils/Sync/MockSyncService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ public override async Task<Stream> PostStreamRaw(SyncStreamOptions options)
165165
var writer = pipe.Writer;
166166

167167
var cts = CancellationTokenSource.CreateLinkedTokenSource(options.CancellationToken);
168+
var listener = syncService.ListenAsync(cts.Token);
168169
_ = Task.Run(async () =>
169170
{
170171
try
171172
{
172-
await foreach (var line in syncService.ListenAsync(cts.Token))
173+
await foreach (var line in listener)
173174
{
174175
var bytes = Encoding.UTF8.GetBytes(line + "\n");
175176
await writer.WriteAsync(bytes);

Tools/Setup/Setup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// </summary>
1111
public class PowerSyncSetup
1212
{
13-
private const string VERSION = "0.4.10";
13+
private const string VERSION = "0.4.11";
1414

1515
private const string GITHUB_BASE_URL = $"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v{VERSION}";
1616
private const string MAVEN_BASE_URL = $"https://repo1.maven.org/maven2/com/powersync/powersync-sqlite-core/{VERSION}";
@@ -239,4 +239,4 @@ static async Task Main(string[] args)
239239
var setup = new PowerSyncSetup();
240240
await setup.RunSetup();
241241
}
242-
}
242+
}

0 commit comments

Comments
 (0)