-
-
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
073b429
commit 9774152
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/Lavalink4NET/Players/Preconditions/AggregateAllPrecondition.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,25 @@ | ||
namespace Lavalink4NET.Players.Preconditions; | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal sealed class AggregateAllPrecondition(ImmutableArray<IPlayerPrecondition> Preconditions) : IPlayerPrecondition | ||
{ | ||
public async ValueTask<bool> CheckAsync(ILavalinkPlayer player, CancellationToken cancellationToken = default) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
ArgumentNullException.ThrowIfNull(player); | ||
|
||
foreach (var precondition in Preconditions) | ||
{ | ||
if (!await precondition.CheckAsync(player, cancellationToken).ConfigureAwait(false)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Lavalink4NET/Players/Preconditions/AggregateAnyPrecondition.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,25 @@ | ||
namespace Lavalink4NET.Players.Preconditions; | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal sealed class AggregateAnyPrecondition(ImmutableArray<IPlayerPrecondition> Preconditions) : IPlayerPrecondition | ||
{ | ||
public async ValueTask<bool> CheckAsync(ILavalinkPlayer player, CancellationToken cancellationToken = default) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
ArgumentNullException.ThrowIfNull(player); | ||
|
||
foreach (var precondition in Preconditions) | ||
{ | ||
if (await precondition.CheckAsync(player, cancellationToken).ConfigureAwait(false)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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