Skip to content

Instantly share code, notes, and snippets.

@Aaronontheweb
Created July 17, 2014 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aaronontheweb/4ecf3a11de54516163e9 to your computer and use it in GitHub Desktop.
Save Aaronontheweb/4ecf3a11de54516163e9 to your computer and use it in GitHub Desktop.
Inline actor - defined solely using lamba functions and delegates
/// <summary>
/// A simple actor implementation that can be defined solely using lamba functions and delegates
/// </summary>
public class Actor : UntypedActor
{
public Actor()
{
Receive = message => base.Unhandled(message);
OnPreStart = () => base.PreStart();
OnPostStop = () => base.PostStop();
OnUnhandled = o => base.Unhandled(o);
OnPreRestart = (exception, o) => base.PreRestart(exception, o);
OnPostRestart = exception => base.PostRestart(exception);
}
public UntypedReceive Receive { get; set; }
public Action OnPostStop { get; set; }
public Action OnPreStart { get; set; }
public Action<object> OnUnhandled { get; set; }
public Action<Exception, object> OnPreRestart { get; set; }
public Action<Exception> OnPostRestart { get; set; }
protected override void PreStart()
{
OnPreStart();
}
protected override void PostStop()
{
OnPostStop();
}
protected override void Unhandled(object message)
{
OnUnhandled(message);
}
protected override void PreRestart(Exception reason, object message)
{
OnPreRestart(reason, message);
}
protected override void PostRestart(Exception reason)
{
OnPostRestart(reason);
}
protected override void OnReceive(object message)
{
Receive(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment