Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions PowerSync/PowerSync.Common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.0.11-alpha.1

- Updated to the latest version (0.4.11) of the core extension.
- `MDSQLiteConnection` now runs query operations on another thread, which stops the caller thread from blocking.
- 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).
- 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.
Expand Down
27 changes: 14 additions & 13 deletions PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ public PowerSyncDatabase(PowerSyncDatabaseOptions options)
Logger = Logger
});

var syncStreamStatusCts = new CancellationTokenSource();
var _ = Task.Run(() =>
var syncStreamStatusCts = CancellationTokenSource.CreateLinkedTokenSource(masterCts.Token);
var syncStreamStatusListener = syncStreamImplementation.ListenAsync(syncStreamStatusCts.Token);
var _ = Task.Run(async () =>
{
foreach (var update in syncStreamImplementation.Listen(syncStreamStatusCts.Token))
await foreach (var update in syncStreamStatusListener)
{
if (update.StatusChanged != null)
{
Expand Down Expand Up @@ -280,36 +281,36 @@ public async Task WaitForFirstSync(PrioritySyncRequest? request = null)
/// <param name="cancellationToken">Optional cancellation token to abort the wait.</param>
public async Task WaitForStatus(Func<SyncStatus, bool> predicate, CancellationToken? cancellationToken = null)
{
var cts = cancellationToken == null
? CancellationTokenSource.CreateLinkedTokenSource(masterCts.Token)
: CancellationTokenSource.CreateLinkedTokenSource(masterCts.Token, cancellationToken.Value);

var statusListener = ListenAsync(cts.Token);

if (predicate(CurrentStatus))
{
cts.Cancel();
return;
}

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

_ = Task.Run(async () =>
{
try
{
await foreach (var update in ListenAsync(cts.Token))
await foreach (var update in statusListener)
{
if (update.StatusChanged != null && predicate(update.StatusChanged))
if ((update.StatusChanged != null) && predicate(update.StatusChanged))
{
cts.Cancel();
tcs.TrySetResult(true);
cts.Cancel();
}
}
}
catch (OperationCanceledException) { }
});

cancellationToken?.Register(() =>
{
cts.Cancel();
tcs.TrySetCanceled();
});

await tcs.Task;
}

Expand Down
1 change: 1 addition & 0 deletions Tests/PowerSync/PowerSync.Common.Tests/GlobalUsing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using FactAttribute = PowerSync.Common.Tests.Utils.FactAttribute;
10 changes: 10 additions & 0 deletions Tests/PowerSync/PowerSync.Common.Tests/Utils/FactAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace PowerSync.Common.Tests.Utils;

[AttributeUsage(AttributeTargets.Method)]
public class FactAttribute : Xunit.FactAttribute
{
public FactAttribute()
{
Timeout = 5000;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ public override async Task<Stream> PostStreamRaw(SyncStreamOptions options)
var writer = pipe.Writer;

var cts = CancellationTokenSource.CreateLinkedTokenSource(options.CancellationToken);
var listener = syncService.ListenAsync(cts.Token);
_ = Task.Run(async () =>
{
try
{
await foreach (var line in syncService.ListenAsync(cts.Token))
await foreach (var line in listener)
{
var bytes = Encoding.UTF8.GetBytes(line + "\n");
await writer.WriteAsync(bytes);
Expand Down
4 changes: 2 additions & 2 deletions Tools/Setup/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// </summary>
public class PowerSyncSetup
{
private const string VERSION = "0.4.10";
private const string VERSION = "0.4.11";

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