Skip to content

Commit 77d33d4

Browse files
authored
feat!: return IAsyncEnumerable from Watch and OnChange (#43)
1 parent 2830a17 commit 77d33d4

19 files changed

Lines changed: 695 additions & 730 deletions

File tree

PowerSync/PowerSync.Common/CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
# PowerSync.Common Changelog
22

3+
## 0.0.11-alpha.1
4+
5+
- 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).
6+
- 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.
7+
8+
```csharp
9+
// Optional cancellation token
10+
var cts = new CancellationTokenSource();
11+
12+
// Register listener synchronously on the calling thread...
13+
var listener = db.Watch<Todo>(
14+
"SELECT * FROM todos",
15+
[],
16+
new SQLWatchOptions { Signal = cts.Token }
17+
);
18+
19+
// ...then listen to changes on another thread
20+
_ = Task.Run(async () =>
21+
{
22+
await foreach (var result in listener)
23+
{
24+
Console.WriteLine($"Number of todos: {result.Length}");
25+
}
26+
}, cts.Token);
27+
28+
// Stop watching by cancelling token
29+
cts.Cancel();
30+
```
31+
332
## 0.0.10-alpha.1
433

534
- Fixed watched queries sometimes resolving to the wrong underlying tables after a schema change.

0 commit comments

Comments
 (0)