Skip to content

Commit

Permalink
more IAsyncDisposable stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wiz0u committed Sep 6, 2024
1 parent 9fe6a9d commit be7027b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Examples/Program_DownloadSavedMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static class Program_DownloadSavedMedia
static async Task Main(string[] _)
{
Console.WriteLine("The program will download photos/medias from messages you send/forward to yourself (Saved Messages)");
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
await using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
var user = await client.LoginUserIfNeeded();
client.OnUpdates += Client_OnUpdates;
Console.ReadKey();
Expand Down
2 changes: 1 addition & 1 deletion Examples/Program_GetAllChats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static string Config(string what)

static async Task Main(string[] _)
{
using var client = new WTelegram.Client(Config);
await using var client = new WTelegram.Client(Config);
var user = await client.LoginUserIfNeeded();
Console.WriteLine($"We are logged-in as {user.username ?? user.first_name + " " + user.last_name} (id {user.id})");

Expand Down
2 changes: 1 addition & 1 deletion Examples/Program_Heroku.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static async Task Main(string[] _)
var store = new PostgreStore(Environment.GetEnvironmentVariable("DATABASE_URL"), Environment.GetEnvironmentVariable("SESSION_NAME"));
// if DB does not contain a session yet, client will be run in interactive mode
Client = new WTelegram.Client(store.Length == 0 ? null : Environment.GetEnvironmentVariable, store);
using (Client)
await using (Client)
{
Client.OnUpdates += Client_OnUpdates;
My = await Client.LoginUserIfNeeded();
Expand Down
2 changes: 1 addition & 1 deletion Examples/Program_ListenUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static async Task Main(string[] _)
Console.WriteLine("The program will display updates received for the logged-in user. Press any key to terminate");
WTelegram.Helpers.Log = (l, s) => System.Diagnostics.Debug.WriteLine(s);
Client = new WTelegram.Client(Environment.GetEnvironmentVariable);
using (Client)
await using (Client)
{
Manager = Client.WithUpdateManager(Client_OnUpdate/*, "Updates.state"*/);
My = await Client.LoginUserIfNeeded();
Expand Down
4 changes: 2 additions & 2 deletions Examples/Program_ReactorError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static async Task Main(string[] _)
}
finally
{
Client?.Dispose();
if (Client != null) await Client.DisposeAsync();
}
}

Expand All @@ -42,7 +42,7 @@ private static async Task Client_OnOther(IObject arg)
while (true)
{
Console.WriteLine("Disposing the client and trying to reconnect in 5 seconds...");
Client?.Dispose();
if (Client != null) await Client.DisposeAsync();
Client = null;
await Task.Delay(5000);
try
Expand Down
5 changes: 4 additions & 1 deletion src/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

namespace WTelegram
{
public partial class Client : IDisposable, IAsyncDisposable
public partial class Client : IDisposable
#if NETCOREAPP2_1_OR_GREATER
, IAsyncDisposable
#endif
{
/// <summary>This event will be called when unsollicited updates/messages are sent by Telegram servers</summary>
/// <remarks>Make your handler <see langword="async"/>, or return <see cref="Task.CompletedTask"/> or <see langword="null"/><br/>See <see href="https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_ReactorError.cs?ts=4#L30">Examples/Program_ReactorError.cs</see> for how to use this<br/>or <see href="https://github.com/wiz0u/WTelegramClient/blob/master/Examples/Program_ListenUpdates.cs?ts=4#L21">Examples/Program_ListenUpdate.cs</see> using the UpdateManager class instead</remarks>
Expand Down

0 comments on commit be7027b

Please sign in to comment.