Skip to content

Commit

Permalink
docs: update docs with new api
Browse files Browse the repository at this point in the history
  • Loading branch information
vmenge committed Jan 21, 2024
1 parent a5aa5d6 commit d6c5a11
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 476 deletions.
10 changes: 4 additions & 6 deletions book/src/SUMMARY.md
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)
74 changes: 0 additions & 74 deletions book/src/handlers.md

This file was deleted.

56 changes: 53 additions & 3 deletions book/src/intro.md
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),
Print
}

#[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;
}
```
115 changes: 0 additions & 115 deletions book/src/lifecycle_management.md

This file was deleted.

11 changes: 11 additions & 0 deletions book/src/process_lifecycle.md
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>
69 changes: 0 additions & 69 deletions book/src/pub_sub.md

This file was deleted.

Loading

0 comments on commit d6c5a11

Please sign in to comment.