Skip to content

Commit

Permalink
Allowed contravariance in actor messages
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutierrez committed Jul 28, 2024
1 parent 8d9da3b commit 0453bc3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Nixie/IActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Nixie;
/// This interface must be implemented by all actors that do not return a response.
/// </summary>
/// <typeparam name="TRequest"></typeparam>
public interface IActor<TRequest> where TRequest : class
public interface IActor<in TRequest> where TRequest : class
{
public Task Receive(TRequest message);
}
2 changes: 1 addition & 1 deletion Nixie/IActorStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Nixie;
/// This actor type supports struct request messages.
/// </summary>
/// <typeparam name="TRequest"></typeparam>
public interface IActorStruct<TRequest> where TRequest : struct
public interface IActorStruct<in TRequest> where TRequest : struct
{
public Task Receive(TRequest message);
}
2 changes: 1 addition & 1 deletion Nixie/IActorStructReply.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Nixie;
/// </summary>
/// <typeparam name="TRequest"></typeparam>
/// <typeparam name="TResponse"></typeparam>
public interface IActorStruct<TRequest, TResponse> where TRequest : struct where TResponse : struct
public interface IActorStruct<in TRequest, TResponse> where TRequest : struct where TResponse : struct
{
/// <summary>
/// Passes a message to the actor and returns a response.
Expand Down
2 changes: 1 addition & 1 deletion Nixie/LazyTaskMethodBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Nixie;

public class LazyTaskMethodBuilder<T>
{
public LazyTaskMethodBuilder() => Task = new LazyTask<T>();
public LazyTaskMethodBuilder() => Task = new();

public static LazyTaskMethodBuilder<T> Create() => new();

Expand Down
2 changes: 1 addition & 1 deletion Nixie/Nixie.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Nixie</PackageId>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<Description>A Lightweight Actor Model Implementation for C#/.NET</Description>
<Authors>Andres Gutierrez</Authors>
<Company>Andres Gutierrez</Company>
Expand Down
21 changes: 21 additions & 0 deletions Nixie/Routers/ActorSystemExtensionsStruct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,27 @@ List<IActorRefStruct<TActor, TRequest>> instances
{
return actorSystem.SpawnStruct<ConsistentHashActorStruct<TActor, TRequest>, TRequest>(null, instances);
}

/// <summary>
/// Creates a Consistent Hash router specifying name and a list of instances
/// </summary>
/// <typeparam name="TActor"></typeparam>
/// <typeparam name="TRequest"></typeparam>
/// <typeparam name="TResponse"></typeparam>
/// <param name="actorSystem"></param>
/// <param name="name"></param>
/// <param name="instances"></param>
/// <returns></returns>
public static IActorRefStruct<ConsistentHashActorStruct<TActor, TRequest>, TRequest>
CreateConsistentHashRouterStruct<TActor, TRequest>(
this ActorSystem actorSystem,
string name,
List<IActorRefStruct<TActor, TRequest>> instances
)
where TActor : IActorStruct<TRequest> where TRequest : struct, IConsistentHashable
{
return actorSystem.SpawnStruct<ConsistentHashActorStruct<TActor, TRequest>, TRequest>(name, instances);
}

/// <summary>
/// Creates a Consistent Hash router specifying name and number of instances
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ To install Nixie into your C#/.NET project, you can use the .NET CLI or the NuGe
#### Using .NET CLI

```shell
dotnet add package Nixie --version 1.0.4
dotnet add package Nixie --version 1.0.5
```

### Using NuGet Package Manager

Search for Nixie and install it from the NuGet package manager UI, or use the Package Manager Console:

```shell
Install-Package Nixie -Version 1.0.4
Install-Package Nixie -Version 1.0.5
```

## Usage
Expand Down

0 comments on commit 0453bc3

Please sign in to comment.