GithubHelp home page GithubHelp logo

akka.net's Introduction

Dagmatic.Akka

Workflows for akka.net

Build Status

Get on NuGet

public class ToyTest : BT<object>
{
    public abstract class Message
    {
        public class ConnectedMsg : Message { }
        public class DisconnectedMsg : Message { }
        public class DoBark : Message { }
        public class DoSleep : Message { }
        public class DoJump : Message { }
        public class DoWake : Message { }
    }

    public ToyTest()
    {
        StartWith(Disconnected(), null);
    }

    TreeMachine.IWorkflow Disconnected() =>
        Receive<Message.ConnectedMsg>(
            Become(Connected)); // Become takes in a Func, in order avoid cycles in graph

    TreeMachine.IWorkflow Connected() =>
        Parallel(ss => ss.AllComplete(), // AllComplete irrelevant when Become overwrites the whole workflow
            Receive<Message.DisconnectedMsg>(
                Become(Disconnected)),
            Spawn(Awake())); // Using Spawn to limit Become scope, Becomes under Spawn overwrite Spawn child
                             // Spawns still belong to their parent, and will be overwritten along with parent
    TreeMachine.IWorkflow Awake() =>
        AllComplete(
            Execute(_ => Sender.Tell("YAWN")),
            Forever( // Forever until Become
                Parallel(ss => ss.AnySucceed(), // Parallel to listen to several message types/conditions
                    Receive<Message.DoBark>(Execute(ctx => Sender.Tell("BARK"))), // Receive is a single callback
                    Receive<Message.DoJump>(Execute(ctx => Sender.Tell("WHEE"))), // use loops to receive again
                    Receive<Message.DoSleep>(Become(Sleeping)))));

    TreeMachine.IWorkflow Sleeping() =>
        AllComplete(
            Execute(_ => Sender.Tell("ZZZZ")),
            Receive<Message.DoWake>( // Ignoring all messages besides DoWake
                Become(Awake))); // But the Parallel in Connected also has a DisconnectedMsg listener
}

[Fact]
public void BTActor_ToyTest()
{
    var bt = Sys.ActorOf(Props.Create(() => new ToyTest()));

    Sys.EventStream.Subscribe(TestActor, typeof(UnhandledMessage));

    Action<object> assertUnhandled = s =>
    {
        bt.Tell(s, TestActor);
        ExpectMsg<UnhandledMessage>(m => m.Message.Equals(s));
    };

    Action<object, object> assertReply = (s, r) =>
    {
        bt.Tell(s, TestActor);
        ExpectMsg(r);
    };

    assertUnhandled("Hey");
    assertUnhandled(new ToyTest.Message.DoBark());
    assertReply(new ToyTest.Message.ConnectedMsg(), "YAWN");
    assertUnhandled(new ToyTest.Message.ConnectedMsg());
    assertUnhandled(new ToyTest.Message.DoWake());
    assertReply(new ToyTest.Message.DoBark(), "BARK");
    assertReply(new ToyTest.Message.DoJump(), "WHEE");
    assertReply(new ToyTest.Message.DoSleep(), "ZZZZ");
    assertUnhandled(new ToyTest.Message.DoBark());
    assertReply(new ToyTest.Message.DoWake(), "YAWN");
    assertReply(new ToyTest.Message.DoBark(), "BARK");

    bt.Tell(new ToyTest.Message.DisconnectedMsg(), TestActor);
    assertUnhandled(new ToyTest.Message.DoBark());
    assertReply(new ToyTest.Message.ConnectedMsg(), "YAWN");
}

akka.net's People

Contributors

dpavlenkov avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

akka.net's Issues

implement workflow refinement

Thinking of workflows as goals represented as subgoal dependency graphs, allow workflows to refine their position in graph by:

  • replacing themselves with another worklow
  • adding worflows in front
  • adding worflows behind

Any other actions? Does this make sense?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.