Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chapter 2.2 - Execute a process #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
- [Getting Started](ch01-00-getting-started.md)
- [How to](ch02-00-how-to.md)
- [Initializing Bastion](ch02-01-initializing-bastion.md)
- [Execute a process](ch02-02-execute-a-process.md)
- [Appendix](appendix-00.md)
- [Definition](definition-01.md)
8 changes: 8 additions & 0 deletions src/appendix-01-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Quick explanation of some words you will encounter.

## Actor Model

TODO

## Backtraces

> To find the cause of something by examining past events.
Expand Down Expand Up @@ -46,3 +50,7 @@ fn main() {
Finished dev [unoptimized + debuginfo] target(s) in 0.79s
Running `target/debug/examples/hide_backtraces`
```

## Future

TODO
4 changes: 4 additions & 0 deletions src/ch02-00-how-to.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# How to

In this section we will talk about the principal features of bastion, with a functional approach.

The examples are just illustrating the purpose explained in the current section, not more, not less. We will complexify them during the book by adding new notions. If you need to have complete use cases you can find them in the [example section][example section] of the bastion repository.

[example section]: https://github.com/bastion-rs/bastion/tree/master/src/bastion/examples
27 changes: 27 additions & 0 deletions src/ch02-02-execute-a-process.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Execute a process

Bastion is an actor-model-like concurrency. In the `Actor Model`\* we find some `Actor` which are made to process computation. In Bastion we have the `Children`.

A `Children` is spawned by using `Bastion::children();`. It take a `init` closure as parameter, it take the new `Children` as an argument and returning it once configured.

## Exec

The new `Children` passed in the `init` closure as parameter, will be used to configure itself. `with_exec();` sets the closure that will be used by every child of this children group. It take a `BastionContext` as parameter and return a `Future`\*.

When a process is started, a **new context** will be assigned. Passed through the `init` closure and poll the future until it complete or abort. The future's output must be a `Result<(), ()>`.

```rs
use bastion::prelude::*;

fn main() {
Bastion::init();
Bastion::start();

Bastion::children(|children| children.with_exec(|_ctx: BastionContext| async { Ok(()) }))
.expect("Couldn't create the children group.");

Bastion::stop();
}
```

\*`Actor Model`: Appendix - Definition \*`Future`: Appendix - Definition