Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for async await suspend-resume mechanics #836

Merged
merged 1 commit into from
Apr 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/core/Akka.Tests/Dispatch/AsyncAwaitSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Dispatch;
using Akka.Event;
using Akka.TestKit;
using Xunit;

namespace Akka.Tests.Dispatch
{
class AsyncActor : ReceiveActor
{
public AsyncActor()
{
Receive<string>(AsyncBehavior.Suspend, async s =>
{
await Task.Yield();
if (s == "stop")
{
Sender.Tell("done");
}
});
}

ILoggingAdapter Log = Context.GetLogger();
}

public class SuspendActor : ReceiveActor
{
public SuspendActor()
Expand Down Expand Up @@ -313,9 +331,23 @@ public async Task Actors_should_be_able_to_reenter()
public async Task Actors_should_be_able_to_suspend_reentrancy()
{
var asker = Sys.ActorOf(Props.Create(() => new SuspendActor()));
var res = await asker.Ask<int>("start", TimeSpan.FromSeconds(555));
var res = await asker.Ask<int>("start", TimeSpan.FromSeconds(5));
res.ShouldBe(0);
}

[Fact]
public async Task Actor_should_be_able_to_resume_suspend()
{
var asker = Sys.ActorOf<AsyncActor>();

for (var i = 0; i < 10; i++)
{
asker.Tell("msg #" + i);
}

var res = await asker.Ask<string>("stop", TimeSpan.FromSeconds(55555));
res.ShouldBe("done");
}
}
}

2 changes: 1 addition & 1 deletion src/core/Akka/Dispatch/ActorTaskScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ await action()
.ContinueWith(
Rethrow,
Faulted,
TaskContinuationOptions.OnlyOnFaulted);
TaskContinuationOptions.None);

//if reentrancy was suspended, make sure we re-enable message processing again
if (behavior == AsyncBehavior.Suspend)
Expand Down