-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
950a87d
commit 351f1b6
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/Lavalink4NET/Players/Preconditions/InlineAsynchronousPrecondition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Lavalink4NET.Players.Preconditions; | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal sealed record class InlineAsynchronousPrecondition(Func<ILavalinkPlayer, CancellationToken, ValueTask<bool>> Precondition) : IPlayerPrecondition | ||
{ | ||
public ValueTask<bool> CheckAsync(ILavalinkPlayer player, CancellationToken cancellationToken = default) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
ArgumentNullException.ThrowIfNull(player); | ||
|
||
return Precondition(player, cancellationToken); | ||
} | ||
} | ||
|
||
internal sealed record class InlineAsynchronousPrecondition<TPlayer>(Func<TPlayer, CancellationToken, ValueTask<bool>> Precondition) : IPlayerPrecondition where TPlayer : ILavalinkPlayer | ||
{ | ||
public async ValueTask<bool> CheckAsync(ILavalinkPlayer player, CancellationToken cancellationToken = default) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
ArgumentNullException.ThrowIfNull(player); | ||
|
||
return player is TPlayer specializedPlayer && await Precondition(specializedPlayer, cancellationToken).ConfigureAwait(false); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Lavalink4NET/Players/Preconditions/InlineSynchronousPrecondition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Lavalink4NET.Players.Preconditions; | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal sealed record class InlineSynchronousPrecondition(Func<ILavalinkPlayer, bool> Precondition) : IPlayerPrecondition | ||
{ | ||
public ValueTask<bool> CheckAsync(ILavalinkPlayer player, CancellationToken cancellationToken = default) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
ArgumentNullException.ThrowIfNull(player); | ||
|
||
return new ValueTask<bool>(Precondition(player)); | ||
} | ||
} | ||
|
||
internal sealed record class InlineSynchronousPrecondition<TPlayer>(Func<TPlayer, bool> Precondition) : IPlayerPrecondition where TPlayer : ILavalinkPlayer | ||
{ | ||
public ValueTask<bool> CheckAsync(ILavalinkPlayer player, CancellationToken cancellationToken = default) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
ArgumentNullException.ThrowIfNull(player); | ||
|
||
return new ValueTask<bool>(player is TPlayer specializedPlayer && Precondition(specializedPlayer)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters