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

WiP Passivation context decorator #1923

Merged
merged 1 commit into from
Feb 12, 2023
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
32 changes: 32 additions & 0 deletions src/Proto.Actor/Context/PassivationContextDecorator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;

namespace Proto.Context;

[PublicAPI]
public static class PassivationContextExtensions
{
public static Props WithPassivationContextDecorator(this Props props, TimeSpan timeout) =>
props.WithContextDecorator(ctx => new PassivationContextDecorator(ctx, timeout));
}
public class PassivationContextDecorator : ActorContextDecorator
{
private readonly IContext _context;
public PassivationContextDecorator(IContext context, TimeSpan timeout) : base(context)
{
_context = context;
context.SetReceiveTimeout(timeout);
}

public override Task Receive(MessageEnvelope envelope)
{
if (envelope.Message is ReceiveTimeout)
{
_context.Stop(_context.Self);
return Task.CompletedTask;
}

return base.Receive(envelope);
}
}
2 changes: 2 additions & 0 deletions src/Proto.TestKit/TestKitException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

namespace Proto.TestKit;

#pragma warning disable RCS1194
public class TestKitException : Exception
#pragma warning restore RCS1194
{
public TestKitException(string message) : base(message)
{
Expand Down