Skip to content

Commit

Permalink
Fix for 1185 receive timeout in async await actor
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing committed Aug 10, 2015
1 parent aa45d71 commit 6474bd7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/core/Akka.Tests/Dispatch/AsyncAwaitSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@

namespace Akka.Tests.Dispatch
{
class ReceiveTimeoutAsyncActor : ReceiveActor
{
private IActorRef _replyTo;
public ReceiveTimeoutAsyncActor()
{
Receive<ReceiveTimeout>(t =>
{
_replyTo.Tell("GotIt");
});
Receive<string>(async s =>
{
_replyTo = Sender;
await Task.Delay(TimeSpan.FromMilliseconds(100));
SetReceiveTimeout(TimeSpan.FromMilliseconds(100));
});
}
}
class AsyncActor : ReceiveActor
{
public AsyncActor()
Expand Down Expand Up @@ -325,6 +343,16 @@ public async Task Actor_should_be_able_to_resume_suspend()
var res = await asker.Ask<string>("stop", TimeSpan.FromSeconds(5));
res.ShouldBe("done");
}


[Fact]
public void Actor_should_be_able_to_ReceiveTimeout_after_async_operation()
{
var actor = Sys.ActorOf<ReceiveTimeoutAsyncActor>();

actor.Tell("hello");
ExpectMsg<string>(m => m == "GotIt");
}
}
}

1 change: 1 addition & 0 deletions src/core/Akka/Dispatch/ActorTaskScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ await action()
//if mailbox was suspended, make sure we re-enable message processing again
mailbox.Resume(MailboxSuspendStatus.AwaitingTask);
context.CheckReceiveTimeout();
},
Outer,
CancellationToken.None,
Expand Down

0 comments on commit 6474bd7

Please sign in to comment.