Skip to content

Commit

Permalink
Replaced Receive(Func<T, Task> handler) by ReceiveAsync(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffCyr committed Mar 3, 2016
1 parent 7a11a93 commit b423519
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/benchmark/PingPong/ClientAsyncActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ClientAsyncActor(IActorRef actor, long repeat, TaskCompletionSource<bool>
{
var received = 0L;
var sent = 0L;
Receive<Messages.Msg>(async m =>
ReceiveAsync<Messages.Msg>(async m =>
{
received++;
if (sent < repeat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ private void SetReceive()
_currentSpecRunActor.Forward(message);
});
Receive<BeginNewSpec>(spec => ReceiveBeginSpecRun(spec));
Receive<EndSpec>(spec => ReceiveEndSpecRun(spec));
ReceiveAsync<EndSpec>(spec => ReceiveEndSpecRun(spec));
Receive<RequestTestRunState>(state => Sender.Tell(TestRunData.Copy(TestRunPassed(TestRunData))));
Receive<SubscribeFactCompletionMessages>(messages => AddSubscriber(messages));
Receive<UnsubscribeFactCompletionMessages>(messages => RemoveSubscriber(messages));
Receive<EndTestRun>(async run =>
ReceiveAsync<EndTestRun>(async run =>
{
//clean up the current spec, if it hasn't been done already
if (_currentSpecRunActor != null)
Expand Down
23 changes: 13 additions & 10 deletions src/core/Akka.Remote/EndpointManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,21 @@ private void Receiving()
* those results will then be piped back to Remoting, who waits for the results of
* listen.AddressPromise.
* */
Receive<Listen>(listen => Listens.ContinueWith<INoSerializationVerificationNeeded>(listens =>
Receive<Listen>(listen =>
{
if (listens.IsFaulted)
Listens.ContinueWith<INoSerializationVerificationNeeded>(listens =>
{
return new ListensFailure(listen.AddressesPromise, listens.Exception);
}
else
{
return new ListensResult(listen.AddressesPromise, listens.Result);
}
}, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default)
.PipeTo(Self));
if (listens.IsFaulted)
{
return new ListensFailure(listen.AddressesPromise, listens.Exception);
}
else
{
return new ListensResult(listen.AddressesPromise, listens.Result);
}
}, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default)
.PipeTo(Self);
});

Receive<ListensResult>(listens =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Tests/Actor/ActorCellSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DummyAsyncActor : ReceiveActor
{
public DummyAsyncActor(AutoResetEvent autoResetEvent)
{
Receive<string>(async m =>
ReceiveAsync<string>(async m =>
{
await Task.Delay(500);
autoResetEvent.Set();
Expand Down
20 changes: 10 additions & 10 deletions src/core/Akka.Tests/Dispatch/AsyncAwaitSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ReceiveTimeoutAsyncActor()
{
_replyTo.Tell("GotIt");
});
Receive<string>(async s =>
ReceiveAsync<string>(async s =>
{
_replyTo = Sender;

Expand All @@ -36,7 +36,7 @@ class AsyncActor : ReceiveActor
{
public AsyncActor()
{
Receive<string>(async s =>
ReceiveAsync<string>(async s =>
{
await Task.Yield();
await Task.Delay(TimeSpan.FromMilliseconds(100));
Expand All @@ -57,7 +57,7 @@ public SuspendActor()
{
state = 1;
});
Receive<string>(async m_ =>
ReceiveAsync<string>(async m_ =>
{
Self.Tell("change");
await Task.Delay(TimeSpan.FromSeconds(1));
Expand All @@ -75,7 +75,7 @@ public class AsyncAwaitActor : ReceiveActor
{
public AsyncAwaitActor()
{
Receive<string>(async _ =>
ReceiveAsync<string>(async _ =>
{
var sender = Sender;
var self = Self;
Expand Down Expand Up @@ -112,7 +112,7 @@ public class Asker : ReceiveActor
{
public Asker(IActorRef other)
{
Receive<string>(async _ =>
ReceiveAsync<string>(async _ =>
{
var sender = Sender;
var self = Self;
Expand Down Expand Up @@ -189,7 +189,7 @@ public class AsyncExceptionActor : ReceiveActor
public AsyncExceptionActor(IActorRef callback)
{
_callback = callback;
Receive<string>(async _ =>
ReceiveAsync<string>(async _ =>
{
await Task.Yield();
ThrowException();
Expand Down Expand Up @@ -374,7 +374,7 @@ public class AsyncExceptionCatcherActor : ReceiveActor

public AsyncExceptionCatcherActor()
{
Receive<string>(async m =>
ReceiveAsync<string>(async m =>
{
_lastMessage = m;
try
Expand Down Expand Up @@ -410,7 +410,7 @@ public class AsyncFailingActor : ReceiveActor
{
public AsyncFailingActor()
{
Receive<string>(async m =>
ReceiveAsync<string>(async m =>
{
ThrowException();
});
Expand Down Expand Up @@ -443,7 +443,7 @@ public class AsyncPipeToDelayActor : ReceiveActor
{
public AsyncPipeToDelayActor()
{
Receive<string>(async msg =>
ReceiveAsync<string>(async msg =>
{
Task.Run(() =>
{
Expand All @@ -460,7 +460,7 @@ public class AsyncReentrantActor : ReceiveActor
{
public AsyncReentrantActor()
{
Receive<string>(async msg =>
ReceiveAsync<string>(async msg =>
{
var sender = Sender;
Task.Run(() =>
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Tests/Routing/TailChoppingSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TailChopTestActor : ReceiveActor

public TailChopTestActor(int sleepTime)
{
Receive<string>(async command =>
ReceiveAsync<string>(async command =>
{
switch (command)
{
Expand Down
8 changes: 7 additions & 1 deletion src/core/Akka/Actor/ReceiveActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ private PartialAction<object> CreateNewHandler(Action configure)
return newHandler;
}

protected void Receive<T>(Func<T,Task> handler)
[Obsolete("Use ReceiveAsync instead. This method will be removed in future versions")]
protected void Receive<T>(Func<T, Task> handler)
{
ReceiveAsync(handler);
}

protected void ReceiveAsync<T>(Func<T,Task> handler)
{
EnsureMayConfigureMessageHandlers();
_matchHandlerBuilders.Peek().Match<T>( m =>
Expand Down

0 comments on commit b423519

Please sign in to comment.