Skip to content

Commit

Permalink
fix: Fix DSharpPlus sample race-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Jan 21, 2024
1 parent d5c5c6f commit 073b429
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions samples/Lavalink4NET.DSharpPlus.ExampleBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.EventArgs;
using Lavalink4NET;
using Lavalink4NET.Extensions;
using Lavalink4NET.Players;
Expand Down Expand Up @@ -46,17 +45,9 @@ await _discordClient
.ConnectAsync()
.ConfigureAwait(false);

var readyTaskCompletionSource = new TaskCompletionSource();

Task SetResult(DiscordClient client, ReadyEventArgs eventArgs)
{
readyTaskCompletionSource.TrySetResult();
return Task.CompletedTask;
}

_discordClient.Ready += SetResult;
await readyTaskCompletionSource.Task.ConfigureAwait(false);
_discordClient.Ready -= SetResult;
await _audioService
.WaitForReadyAsync(stoppingToken)
.ConfigureAwait(false);

var playerOptions = new LavalinkPlayerOptions
{
Expand Down

0 comments on commit 073b429

Please sign in to comment.