All Projects → LeonHartley → Coerce Rs

LeonHartley / Coerce Rs

Coerce - an asynchronous (async/await) Actor runtime and cluster framework for Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Coerce Rs

Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (+198.7%)
Mutual labels:  async, asynchronous, async-await, await
Csp
Communicating Sequential Processes in JavaScript
Stars: ✭ 33 (-85.71%)
Mutual labels:  async, asynchronous, await
Blockly Gamepad
A Blockly extension designed to develop games (made with love ❤)
Stars: ✭ 18 (-92.21%)
Mutual labels:  async, asynchronous, await
Asyncex
A helper library for async/await.
Stars: ✭ 2,794 (+1109.52%)
Mutual labels:  async, async-await, await
Actor Framework
An Open Source Implementation of the Actor Model in C++
Stars: ✭ 2,637 (+1041.56%)
Mutual labels:  async, actor-model, actors
Riker
Easily build efficient, highly concurrent and resilient applications. An Actor Framework for Rust.
Stars: ✭ 745 (+222.51%)
Mutual labels:  async, actor-model, actors
Asyncorm
Fully Async ORM inspired in django's
Stars: ✭ 182 (-21.21%)
Mutual labels:  async, asynchronous, async-await
Async Sema
Semaphore using `async` and `await`
Stars: ✭ 326 (+41.13%)
Mutual labels:  async, asynchronous, await
Radon
Object oriented state management solution for front-end development.
Stars: ✭ 80 (-65.37%)
Mutual labels:  async, asynchronous, async-await
Aiormq
Pure python AMQP 0.9.1 asynchronous client library
Stars: ✭ 112 (-51.52%)
Mutual labels:  async, asynchronous, async-await
Async Backplane
Simple, Erlang-inspired fault-tolerance framework for Rust Futures.
Stars: ✭ 113 (-51.08%)
Mutual labels:  async, asynchronous, async-await
P Map
Map over promises concurrently
Stars: ✭ 639 (+176.62%)
Mutual labels:  async, async-await, await
Transmittable Thread Local
📌 TransmittableThreadLocal (TTL), the missing Java™ std lib(simple & 0-dependency) for framework/middleware, provide an enhanced InheritableThreadLocal that transmits values between threads even using thread pooling components.
Stars: ✭ 4,678 (+1925.11%)
Mutual labels:  async, asynchronous, distributed
P Iteration
Utilities that make array iteration easy when using async/await or Promises
Stars: ✭ 337 (+45.89%)
Mutual labels:  async, async-await, await
Azos
A to Z Sky Operating System / Microservice Chassis Framework
Stars: ✭ 137 (-40.69%)
Mutual labels:  actor-model, distributed, cluster
Ea Async
EA Async implements async-await methods in the JVM.
Stars: ✭ 1,085 (+369.7%)
Mutual labels:  async, asynchronous, async-await
theater
Actor framework for Dart. This package makes it easier to work with isolates, create clusters of isolates.
Stars: ✭ 29 (-87.45%)
Mutual labels:  actors, cluster, actor-model
xtra
🎭 A tiny actor framework
Stars: ✭ 111 (-51.95%)
Mutual labels:  asynchronous, actor-model, async-await
Memento
Fairly basic redis-like hashmap implementation on top of a epoll TCP server.
Stars: ✭ 74 (-67.97%)
Mutual labels:  async, distributed, cluster
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (-42.42%)
Mutual labels:  async, asynchronous, async-await

Coerce crates.io coerce-rs tests

Coerce is an asynchronous (async/await) Actor runtime for Rust. It allows for extremely simple yet powerful actor-based multithreaded application development.

async/await Actors

An actor is just another word for a unit of computation. It can have mutable state, it can receive messages and perform actions. One caveat though.. It can only do one thing at a time. This can be useful because it can alleviate the need for thread synchronisation, usually achieved by locking (using Mutex, RwLock etc).

How is this achieved in Coerce?

Coerce uses Tokio's MPSC channels (tokio::sync::mpsc::channel), every actor created spawns a task listening to messages from a Receiver, handling and awaiting the result of the message. Every reference (ActorRef<A: Actor>) holds a Sender<M> where A: Handler<M>, which can be cloned.

Actors can be stopped and actor references can be retrieved by ID from anywhere in your application. IDs are String but if an ID isn't provided upon creation, a new Uuid will be generated. Anonymous actors are automatically dropped (and Stopped) when all references are dropped. Tracked actors (using global fn new_actor) must be stopped.

Example

pub struct EchoActor;

#[async_trait]
impl Actor for EchoActor {}

pub struct EchoMessage(String);

impl Message for EchoMessage {
    type Result = String;
}

#[async_trait]
impl Handler<EchoMessage> for EchoActor {
    async fn handle(
        &mut self,
        message: EchoMessage,
        _ctx: &mut ActorContext,
    ) -> String {
        message.0.clone()
    }
}

pub async fn run() {
    let mut sys = ActorSystem::new();
    
    let mut actor = EchoActor.into_actor(None, &mut sys).await.unwrap();

    let hello_world = "hello, world".to_string();
    let result = actor.send(EchoMessage(hello_world.clone())).await;
    
    assert_eq!(result, Ok(hello_world));
}

Timer Example

pub struct EchoActor;

#[async_trait]
impl Actor for EchoActor {}

pub struct EchoMessage(String);

impl Message for EchoMessage {
    type Result = String;
}

pub struct PrintTimer(String);

impl TimerTick for PrintTimer {}

#[async_trait]
impl Handler<PrintTimer> for EchoActor {
    async fn handle(&mut self, msg: PrintTimer, _ctx: &mut ActorContext) {
        println!("{}", msg.0);
    }
}

pub async fn run() {
    let mut sys = ActorSystem::new();
    let mut actor = EchoActor.into_actor(None, &mut sys).await.unwrap();

    let hello_world = "hello world!".to_string();

    // print "hello world!" every 5 seconds
    let timer = Timer::start(actor.clone(), Duration::from_secs(5), TimerTick(hello_world));
    
    // timer is stopped when handle is out of scope or can be stopped manually by calling `.stop()`
    sleep(Duration::from_secs(20)).await;
    timer.stop();
}
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].