-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
208 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
# Summary | ||
|
||
- [Introduction](intro.md) | ||
- [Spawning a Process](./spawning_a_process.md) | ||
- [Handlers](./handlers.md) | ||
- [The Reply<T,E> type](./reply.md) | ||
- [Lifecycle Management](./lifecycle_management.md) | ||
- [Pub / Sub](./pub_sub.md) | ||
- [Testing](./testing.md) | ||
- [What is a Process?](./what_is_a_process.md) | ||
- [Working with Processes](./wroking_with_processes.md) | ||
- [Process Lifecycle](./process_lifecycle.md) | ||
- [Supervision](./supervision.md) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,57 @@ | ||
> This is out of date. Will be updated soon. | ||
# Introduction | ||
This guide introduces `speare`, covering `Process` creation, message handling, and essential library features. The objective is to provide clear, concise instructions for effectively utilizing `speare` in your Rust projects. | ||
|
||
## What is `speare`? | ||
`speare` is a Rust library designed to simplify the process of actor-based concurrency. It provides an abstraction over [tokio green threads](https://tokio.rs/tokio/tutorial/spawning#tasks) and [flume channels](https://github.com/zesterer/flume), allowing for easier management of tokio threads and efficient message passing between them. With `speare`, each `Process` owns its data and lives on its own green thread, reducing the risks of deadlocks and encouraging a modular design. No more `Arc<Mutex<T>>` everywhere :) | ||
`speare` is a Rust library designed to simplify the process of actor-based concurrency. It provides an abstraction over [tokio green threads](https://tokio.rs/tokio/tutorial/spawning#tasks) and [flume channels](https://github.com/zesterer/flume), allowing for easier management of tokio threads and efficient message passing between them. `speare` revolves around a main abstraction: `Process` -- which lives on its own green thread owning its data, reducing the risks of deadlocks and encouraging a modular design. No more `Arc<Mutex<T>>` everywhere :) | ||
|
||
## Quick Look | ||
Below is an example of a very minimal `Counter` `Process`. | ||
|
||
```rust | ||
use speare::*; | ||
use async_trait::async_trait; | ||
use tokio::time; | ||
|
||
struct Counter { | ||
count: u32, | ||
} | ||
|
||
enum CounterMsg { | ||
Add(u32), | ||
Subtract(u32), | ||
} | ||
|
||
#[async_trait] | ||
impl Process for Counter { | ||
type Props = (); | ||
type Msg = CounterMsg; | ||
type Err = (); | ||
|
||
async fn init(ctx: &mut Ctx<Self>) -> Result<Self, Self::Err> { | ||
Ok(Counter { count: 0 }) | ||
} | ||
|
||
async fn handle(&mut self, msg: Self::Msg, ctx: &mut Ctx<Self>) -> Result<(), Self::Err> { | ||
match msg { | ||
CounterMsg::Add(n) => self.count += n, | ||
CounterMsg::Subtract(n) => self.count -= n, | ||
CounterMsg::Print => println!("Count is {}", self.count) | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let mut node = Node::default(); | ||
let counter = node.spawn::<Counter>(()); | ||
counter.send(CounterMsg::Add(5)); | ||
counter.send(CounterMsg::Subtract(2)); | ||
counter.send(CounterMsg::Print); // will print 3 | ||
|
||
// We wait so the program doesn't end before we print. | ||
time::sleep(Duration::from_millis(1)).await; | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
TBD 🏗️ | ||
|
||
<p hidden> | ||
process lifecycle | ||
- process spawns and lives in memory forever until its stopped | ||
- stopped by its parent being stopped, by being stopped manually or by its parent supervision strategy | ||
- when a process is spawned, the init method is called to create the process instance | ||
- when a process is stopped the exit method is called. | ||
- when a process is restarted, the exit method is first called, and then the init to create a new instance of the process. the handle remains the same though. | ||
</p> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.