All Projects → insanitybit → aktors

insanitybit / aktors

Licence: MIT License
Rust actor library with a bit of inspiration from Akka/Pykka

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to aktors

rust-lp-modeler
Lp modeler written in Rust
Stars: ✭ 75 (+70.45%)
Mutual labels:  rust-library
transit
Massively real-time city transit streaming application
Stars: ✭ 20 (-54.55%)
Mutual labels:  actor-model
bmemcached-rs
Rust binary memcached implementation
Stars: ✭ 24 (-45.45%)
Mutual labels:  rust-library
gen browser
Transparent bi-directional communication for clients, servers and more
Stars: ✭ 67 (+52.27%)
Mutual labels:  actor-model
dogactor
Distributed Systems,Based on Actor Model
Stars: ✭ 70 (+59.09%)
Mutual labels:  actor-model
JKI-State-Machine-Objects
Object-oriented framework for LabVIEW based on the JKI State Machine
Stars: ✭ 82 (+86.36%)
Mutual labels:  actor-model
protoactor-go
Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
Stars: ✭ 4,138 (+9304.55%)
Mutual labels:  actor-model
digitalocean
A prototype API for Digital Ocean.
Stars: ✭ 35 (-20.45%)
Mutual labels:  rust-library
trickster
user-friendly linux memory hacking library
Stars: ✭ 50 (+13.64%)
Mutual labels:  rust-library
warc
⚙️ A Rust library for reading and writing WARC files
Stars: ✭ 26 (-40.91%)
Mutual labels:  rust-library
traffic
Massively real-time traffic streaming application
Stars: ✭ 25 (-43.18%)
Mutual labels:  actor-model
serial test
Allows for the creation of serialised Rust tests
Stars: ✭ 105 (+138.64%)
Mutual labels:  rust-library
reacted
Actor based reactive java framework for microservices in local and distributed environment
Stars: ✭ 17 (-61.36%)
Mutual labels:  actor-model
vpsearch
C library for finding nearest (most similar) element in a set
Stars: ✭ 27 (-38.64%)
Mutual labels:  rust-library
murmur3
A rust implementation of murmur3
Stars: ✭ 48 (+9.09%)
Mutual labels:  rust-library
theater
Actor framework for Dart. This package makes it easier to work with isolates, create clusters of isolates.
Stars: ✭ 29 (-34.09%)
Mutual labels:  actor-model
polyrhythm
A 3Kb full-stack async effect management toolkit over RxJS. Uses a Pub-Sub paradigm to orchestrate Observables in Node, or the browser (ala Redux Saga). Exports: channel, listen, filter, trigger, after.
Stars: ✭ 23 (-47.73%)
Mutual labels:  actor-model
maildir
A simple library to deal with maildir folders
Stars: ✭ 19 (-56.82%)
Mutual labels:  rust-library
fixie-trie
Compact tries for fixed-width keys
Stars: ✭ 23 (-47.73%)
Mutual labels:  rust-library
sonata
Actor-based DDD-first programming language
Stars: ✭ 23 (-47.73%)
Mutual labels:  actor-model

Rust actor library with a bit of inspiration from Akka/Pykka

Built with the 'fibers' crate.

Example

Actors

We first declare our MyActor struct like any other. We take a 'handle' so that we can spawn child actors. (Note that the id is entirely unnecessary, an ActorRef will have its own unique identifier.)

    struct MyActor<H>
        where H: Send + Spawn + Clone + 'static
    {
        handle: H,
        id: String,
    }

    impl<H> MyActor<H>
        where H: Send + Spawn + Clone + 'static
    {
        pub fn new(h: H) -> MyActor<H> {
            MyActor {
                handle: h,
                id: Uuid::new_v4().to_string(),
            }
        }
    }

We then impl Actor for MyActor. We get a message (Box<Any + Send>) and we downcast it to the type we expect.

We then create a child actor and send it its own message (our message + 1).

This will loop (concurrently, yielding after each on_message call) forever, counting eternally.

    impl<H> Actor for MyActor<H>
        where H: Send + Spawn + Clone + 'static
    {
        fn on_message(&mut self, msg: Box<Any + Send>) {
            if let Some(number) = msg.downcast_ref::<u64>() {
                if number % 1000 == 0 {
                    println!("{} got {}", self.id, number);
                }

                //                if *number == 0 {panic!("zero!")};
                let new_actor = Box::new(MyActor::new(self.handle.clone())) as Box<Actor>;
                let actor_ref = actor_of(self.handle.clone(), new_actor);
                actor_ref.sender.send(Box::new(number + 1));
                drop(actor_ref);
            } else {
                panic!("downcast error");
            }
        }
    }

To actually execute the actor we need to create an Execution context, and use the actor_of function.

    let system = ThreadPoolExecutor::with_thread_count(2).unwrap();

    let actor = MyActor::new(system.handle());
    let mut actor_ref = actor_of(system.handle(), Box::new(actor));
    actor_ref.send(Box::new(0 as u64));
    drop(actor_ref);

    let _ = system.run();

Supervisors

Using the above MyActor we create a ChildSpec, which will return a MyActor. The supervisor uses this function to generate new actors and replace dead ones.

We then create the predefined Supervisor, and pass it to actor_of.

We can then send messages to the supervisor, using the SuperVisorMessage structure. We provide the name we gave to the child, which the supervisor uses internally to route messages.

(Currently supervisors do not catch panics - this will change)

        let system = ThreadPoolExecutor::with_thread_count(2).unwrap();
        let handle = system.handle();

        let child_spec = ChildSpec::new("worker child".to_owned(),
                                        move |handle| Box::new(MyActor::new(handle)) as Box<Actor>,
                                        Restart::Temporary,
                                        Shutdown::Eventually,
                                        ActorKind::Worker);

        let mut supervisor_ref =
            actor_of(handle.clone(),
                     Box::new(Supervisor::new(handle.clone(), vec![child_spec])) as Box<Actor>);

        supervisor_ref.send(Box::new(SupervisorMessage {
            id: "worker child".to_owned(),
            msg: Box::new(1000000 as u64),
        }));


        drop(supervisor_ref);

        let _ = system.run();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].