Skip to content

Commit

Permalink
Merge pull request #5 from Cysharp/feature/ChangeSignatureToIEnumerable
Browse files Browse the repository at this point in the history
Change the parameter ImmutableArray to IEnumerable
  • Loading branch information
mayuki authored Dec 27, 2024
2 parents e322bbc + b3b03ef commit c8c590d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 31 deletions.
8 changes: 4 additions & 4 deletions src/Multicaster.Distributed.Nats/NatsGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ public void Write(ReadOnlyMemory<byte> payload)
}
}

public T Except(ImmutableArray<TKey> excludes)
public T Except(IEnumerable<TKey> excludes)
{
ThrowIfDisposed();
return _proxyFactory.Create<T>(new NatsPublishWriter(_connection, _subject, excludes, null), _serializer, NotSupportedRemoteClientResultPendingTaskRegistry.Instance);
return _proxyFactory.Create<T>(new NatsPublishWriter(_connection, _subject, [..excludes], null), _serializer, NotSupportedRemoteClientResultPendingTaskRegistry.Instance);
}

public T Only(ImmutableArray<TKey> targets)
public T Only(IEnumerable<TKey> targets)
{
ThrowIfDisposed();
return _proxyFactory.Create<T>(new NatsPublishWriter(_connection, _subject, ImmutableArray<TKey>.Empty, targets), _serializer, NotSupportedRemoteClientResultPendingTaskRegistry.Instance);
return _proxyFactory.Create<T>(new NatsPublishWriter(_connection, _subject, ImmutableArray<TKey>.Empty, [..targets]), _serializer, NotSupportedRemoteClientResultPendingTaskRegistry.Instance);
}

public T Single(TKey target)
Expand Down
8 changes: 4 additions & 4 deletions src/Multicaster.Distributed.Redis/RedisGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ public void Write(ReadOnlyMemory<byte> payload)
}
}

public T Except(ImmutableArray<TKey> excludes)
public T Except(IEnumerable<TKey> excludes)
{
ThrowIfDisposed();
return _proxyFactory.Create<T>(new RedisPublishWriter(_subscriber, _channel, excludes, null), _serializer, NotSupportedRemoteClientResultPendingTaskRegistry.Instance);
return _proxyFactory.Create<T>(new RedisPublishWriter(_subscriber, _channel, [..excludes], null), _serializer, NotSupportedRemoteClientResultPendingTaskRegistry.Instance);
}

public T Only(ImmutableArray<TKey> targets)
public T Only(IEnumerable<TKey> targets)
{
ThrowIfDisposed();
return _proxyFactory.Create<T>(new RedisPublishWriter(_subscriber, _channel, ImmutableArray<TKey>.Empty, targets), _serializer, NotSupportedRemoteClientResultPendingTaskRegistry.Instance);
return _proxyFactory.Create<T>(new RedisPublishWriter(_subscriber, _channel, ImmutableArray<TKey>.Empty, [..targets]), _serializer, NotSupportedRemoteClientResultPendingTaskRegistry.Instance);
}

public T Single(TKey target)
Expand Down
14 changes: 3 additions & 11 deletions src/Multicaster/IMulticastGroup.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System.Collections.Immutable;

namespace Cysharp.Runtime.Multicast;
namespace Cysharp.Runtime.Multicast;

public interface IMulticastGroup<TKey, TReceiver>
where TKey : IEquatable<TKey>
{
TReceiver All { get; }
TReceiver Except(ImmutableArray<TKey> excludes);
TReceiver Only(ImmutableArray<TKey> targets);
TReceiver Except(IEnumerable<TKey> excludes);
TReceiver Only(IEnumerable<TKey> targets);
TReceiver Single(TKey target);
}

Expand All @@ -32,10 +30,4 @@ public static class MulticastGroupExtensions
public static TReceiver Except<TKey, TReceiver>(this IMulticastGroup<TKey, TReceiver> group, TKey exclude)
where TKey : IEquatable<TKey>
=> group.Except([exclude]);
public static TReceiver Except<TKey, TReceiver>(this IMulticastGroup<TKey, TReceiver> group, IReadOnlyList<TKey> excludes)
where TKey : IEquatable<TKey>
=> group.Except([.. excludes]);
public static TReceiver Only<TKey, TReceiver>(this IMulticastGroup<TKey, TReceiver> group, IReadOnlyList<TKey> targets)
where TKey : IEquatable<TKey>
=> group.Only([..targets]);
}
10 changes: 4 additions & 6 deletions src/Multicaster/InMemory/InMemoryGroupProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Concurrent;
using System.Collections.Immutable;

using static System.Net.Mime.MediaTypeNames;

namespace Cysharp.Runtime.Multicast.InMemory;

public class InMemoryGroupProvider : IMulticastGroupProvider
Expand Down Expand Up @@ -48,16 +46,16 @@ public InMemoryGroup(string name, IInMemoryProxyFactory proxyFactory, Action<InM
All = _proxyFactory.Create(_receivers);
}

public T Except(ImmutableArray<TKey> excludes)
public T Except(IEnumerable<TKey> excludes)
{
ThrowIfDisposed();
return _proxyFactory.Except(_receivers, excludes);
return _proxyFactory.Except(_receivers, [..excludes]);
}

public T Only(ImmutableArray<TKey> targets)
public T Only(IEnumerable<TKey> targets)
{
ThrowIfDisposed();
return _proxyFactory.Only(_receivers, targets);
return _proxyFactory.Only(_receivers, [..targets]);
}

public T Single(TKey target)
Expand Down
8 changes: 4 additions & 4 deletions src/Multicaster/Remoting/RemoteGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ public int Count()
return _receivers.Count;
}

public T Except(ImmutableArray<TKey> excludes)
public T Except(IEnumerable<TKey> excludes)
{
ThrowIfDisposed();
return _proxyFactory.Except<TKey, T>(_receivers, excludes, _serializer, _pendingTasks);
return _proxyFactory.Except<TKey, T>(_receivers, [..excludes], _serializer, _pendingTasks);
}

public T Only(ImmutableArray<TKey> targets)
public T Only(IEnumerable<TKey> targets)
{
ThrowIfDisposed();
return _proxyFactory.Only<TKey, T>(_receivers, targets, _serializer, _pendingTasks);
return _proxyFactory.Only<TKey, T>(_receivers, [..targets], _serializer, _pendingTasks);
}

public T Single(TKey target)
Expand Down
4 changes: 2 additions & 2 deletions src/Multicaster/Remoting/RemoteGroupProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ Action<RemoteCompositeGroup<TKey, T>> disposeAction
All = memoryProxyFactory.Create<TKey, T>(ReceiverHolder.CreateImmutable<TKey, T>(_memoryGroup.All, _remoteGroup.All));
}

public T Except(ImmutableArray<TKey> excludes)
public T Except(IEnumerable<TKey> excludes)
{
ThrowIfDisposed();
return _memoryProxyFactory.Create(ReceiverHolder.CreateImmutable<TKey, T>(_memoryGroup.Except(excludes), _remoteGroup.Except(excludes)));
}

public T Only(ImmutableArray<TKey> targets)
public T Only(IEnumerable<TKey> targets)
{
ThrowIfDisposed();
return _memoryProxyFactory.Create(ReceiverHolder.CreateImmutable<TKey, T>(_memoryGroup.Only(targets), _remoteGroup.Only(targets)));
Expand Down

0 comments on commit c8c590d

Please sign in to comment.