Skip to content

Commit

Permalink
Simplify may interlave message extraction helper with predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
yevhen committed Nov 21, 2019
1 parent 75a4adf commit da9546e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
12 changes: 3 additions & 9 deletions Source/Orleankka.Runtime/InvokeMethodRequestExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;

using Orleans.CodeGeneration;
using Orleans.Concurrency;
Expand All @@ -8,13 +7,8 @@ namespace Orleankka
{
public static class InvokeMethodRequestExtensions
{
public static bool Any(this InvokeMethodRequest request, params Type[] messages)
{
var message = request.Message().GetType();
return messages.Any(x => x == message);
}

public static T Message<T>(this InvokeMethodRequest request) => (T) request.Message();
public static bool Message(this InvokeMethodRequest request, Func<object, bool> predicate) =>
predicate(request.Message());

public static object Message(this InvokeMethodRequest request)
{
Expand All @@ -30,6 +24,6 @@ public static object Message(this InvokeMethodRequest request)
}

static object UnwrapImmutable(object item) =>
item is Immutable<object> ? ((Immutable<object>)item).Value : item;
item is Immutable<object> immutable ? immutable.Value : item;
}
}
5 changes: 2 additions & 3 deletions Tests/Orleankka.Tests/Features/Reentrant_messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ public interface ITestReentrantStreamConsumerActor : IActorGrain
[MayInterleave(nameof(Interleave))]
public class TestReentrantStreamConsumerActor : DispatchActorGrain, ITestReentrantStreamConsumerActor
{
public static bool Interleave(InvokeMethodRequest req) => req.Any(
typeof(GetStreamMessagesInProgress),
typeof(int)); // 1-st stream message type
public static bool Interleave(InvokeMethodRequest req) =>
req.Message(x => x is GetStreamMessagesInProgress || x is int); // int is 1-st stream message type

readonly List<object> streamMessagesInProgress = new List<object>();
List<object> On(GetStreamMessagesInProgress x) => streamMessagesInProgress;
Expand Down

0 comments on commit da9546e

Please sign in to comment.