From 75c3f171f7b91580efb1d9cdea6940a01a25c220 Mon Sep 17 00:00:00 2001 From: oScape Date: Sun, 9 May 2021 17:32:16 +0200 Subject: [PATCH 1/2] first part --- src/SUMMARY.md | 1 + src/appendix-01-definition.md | 8 ++++++++ src/ch02-00-how-to.md | 4 ++++ src/ch02-02-execute-a-process.md | 28 ++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 src/ch02-02-execute-a-process.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 0f610d6..2d93a68 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) diff --git a/src/appendix-01-definition.md b/src/appendix-01-definition.md index 1d84db3..463173c 100644 --- a/src/appendix-01-definition.md +++ b/src/appendix-01-definition.md @@ -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. @@ -46,3 +50,7 @@ fn main() { Finished dev [unoptimized + debuginfo] target(s) in 0.79s Running `target/debug/examples/hide_backtraces` ``` + +## Future + +TODO \ No newline at end of file diff --git a/src/ch02-00-how-to.md b/src/ch02-00-how-to.md index 57131a2..f48116c 100644 --- a/src/ch02-00-how-to.md +++ b/src/ch02-00-how-to.md @@ -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 diff --git a/src/ch02-02-execute-a-process.md b/src/ch02-02-execute-a-process.md new file mode 100644 index 0000000..1315815 --- /dev/null +++ b/src/ch02-02-execute-a-process.md @@ -0,0 +1,28 @@ +# 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 \ No newline at end of file From 3d99ddfcc45f7d9bdcaa3ce89275746d80b2b416 Mon Sep 17 00:00:00 2001 From: oScape Date: Sun, 9 May 2021 17:33:58 +0200 Subject: [PATCH 2/2] format --- src/appendix-01-definition.md | 2 +- src/ch02-00-how-to.md | 4 ++-- src/ch02-02-execute-a-process.md | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/appendix-01-definition.md b/src/appendix-01-definition.md index 463173c..d69db0c 100644 --- a/src/appendix-01-definition.md +++ b/src/appendix-01-definition.md @@ -53,4 +53,4 @@ fn main() { ## Future -TODO \ No newline at end of file +TODO diff --git a/src/ch02-00-how-to.md b/src/ch02-00-how-to.md index f48116c..79eea7f 100644 --- a/src/ch02-00-how-to.md +++ b/src/ch02-00-how-to.md @@ -2,6 +2,6 @@ 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. +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 +[example section]: https://github.com/bastion-rs/bastion/tree/master/src/bastion/examples diff --git a/src/ch02-02-execute-a-process.md b/src/ch02-02-execute-a-process.md index 1315815..915dce2 100644 --- a/src/ch02-02-execute-a-process.md +++ b/src/ch02-02-execute-a-process.md @@ -24,5 +24,4 @@ fn main() { } ``` -\*`Actor Model`: Appendix - Definition -\*`Future`: Appendix - Definition \ No newline at end of file +\*`Actor Model`: Appendix - Definition \*`Future`: Appendix - Definition