Skip to content

Commit cc5168c

Browse files
committed
Improve controller disposal
1 parent b65e230 commit cc5168c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Parse/Platform/LiveQueries/ParseLiveQueryController.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Parse.Platform.LiveQueries;
1717
/// The ParseLiveQueryController is responsible for managing live query subscriptions, maintaining a connection
1818
/// to the Parse LiveQuery server, and handling real-time updates from the server.
1919
/// </summary>
20-
public class ParseLiveQueryController : IParseLiveQueryController, IDisposable
20+
public class ParseLiveQueryController : IParseLiveQueryController, IDisposable, IAsyncDisposable
2121
{
2222
private IParseDataDecoder Decoder { get; }
2323
private IWebSocketClient WebSocketClient { get; }
@@ -577,6 +577,22 @@ public void Dispose()
577577
GC.SuppressFinalize(this);
578578
}
579579

580+
/// <summary>
581+
/// Asynchronously releases the resources used by the <see cref="ParseLiveQueryController"/> instance.
582+
/// </summary>
583+
/// <returns>
584+
/// A <see cref="ValueTask"/> representing the asynchronous dispose operation.
585+
/// </returns>
586+
/// <remarks>
587+
/// This method is called to perform an asynchronous disposal of the resources held by the current
588+
/// instance. It suppresses finalization of the object to optimize resource cleanup.
589+
/// </remarks>
590+
public async ValueTask DisposeAsync()
591+
{
592+
await CloseAsync();
593+
GC.SuppressFinalize(this);
594+
}
595+
580596
/// <summary>
581597
/// Releases the resources used by the <see cref="ParseLiveQueryController"/> instance.
582598
/// </summary>
@@ -590,7 +606,8 @@ private void Dispose(bool disposing)
590606
return;
591607
if (disposing)
592608
{
593-
CloseAsync().ConfigureAwait(false).GetAwaiter().GetResult();
609+
// For sync disposal, the best effort cleanup without waiting
610+
_ = Task.Run(async () => await CloseAsync());
594611
}
595612
disposed = true;
596613
}

0 commit comments

Comments
 (0)