Skip to content

Commit 5402d78

Browse files
committed
cleanup comments
1 parent 6b36aa4 commit 5402d78

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ private async IAsyncEnumerable<WatchOnChangeEvent> OnRawTableChange(
10021002

10031003
if (throttleMs <= 0)
10041004
{
1005-
// Fast path: no throttling
1005+
// No throttling
10061006
HashSet<string> changedTables = new();
10071007
await foreach (var e in listener)
10081008
{
@@ -1015,7 +1015,7 @@ private async IAsyncEnumerable<WatchOnChangeEvent> OnRawTableChange(
10151015
yield break;
10161016
}
10171017

1018-
// Throttled path: Task.WhenAny loop with leading-edge emit
1018+
// Leading + trailing edge throttle
10191019
var listenerEnumerator = listener.GetAsyncEnumerator(token);
10201020
try
10211021
{
@@ -1058,11 +1058,14 @@ private async IAsyncEnumerable<WatchOnChangeEvent> OnRawTableChange(
10581058
if (accumulated.Count > 0)
10591059
{
10601060
var now = Stopwatch.GetTimestamp();
1061+
1062+
// There's a nice built-in method for this (Stopwatch.GetElapsedTime), but
1063+
// it's not supported in .NET 6.0. :(
10611064
var elapsedMs = (now - lastYieldTime) * 1000.0 / Stopwatch.Frequency;
10621065

10631066
if (elapsedMs >= throttleMs)
10641067
{
1065-
// Leading edge: emit immediately
1068+
// First event in series - fire immediately and start collecting future events
10661069
lastYieldTime = now;
10671070
yield return new WatchOnChangeEvent { ChangedTables = [.. accumulated] };
10681071
accumulated.Clear();

0 commit comments

Comments
 (0)