Skip to content

Commit 55a9b4b

Browse files
authored
Fix readme and add simple example (#7)
* Fix readme and add simple example * Bump version on readme
1 parent 65ffbf6 commit 55a9b4b

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

README.md

+19-10
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ Fort is proc macro attribute crate for Bastion.
55
## Usage
66
```toml
77
[dependencies]
8-
fort = "0.2"
8+
fort = "0.3"
99
bastion = "0.3.*"
1010
```
1111

1212
You can directly use fort to load work onto the root supervisor with:
1313
```rust
1414
#[fort::root]
15-
fn main() {
15+
async fn main(_: BastionContext) -> Result<(), ()> {
1616
println!("Running in Bastion runtime!");
17+
Ok(())
1718
}
1819
```
1920

2021
Make your program fault-tolerant with `fort`:
2122
```rust
2223
#[fort::root]
23-
fn main() {
24+
async fn main(_: BastionContext) -> Result<(), ()> {
2425
loop {
2526
println!("Undying main!");
2627
panic!("Error")
@@ -30,9 +31,12 @@ fn main() {
3031

3132
You want to spawn multiple process
3233
```rust
33-
#[fort::root(redundancy = 3)]
34-
fn main() {
35-
println!("Running in Bastion runtime!");
34+
#[fort::root(redundancy = 10)]
35+
async fn main(_: BastionContext) -> Result<(), ()> {
36+
loop {
37+
println!("Undying main!");
38+
panic!("Error")
39+
}
3640
}
3741
```
3842

@@ -43,13 +47,18 @@ use std::io::Write;
4347
use std::net::TcpListener;
4448

4549
#[fort::root]
46-
fn main() {
50+
async fn main(_: BastionContext) -> Result<(), ()> {
4751
let listener = TcpListener::bind("127.0.0.1:2278").unwrap();
4852
println!("TCP server started at 127.0.0.1:2278");
4953
for stream in listener.incoming() {
50-
let mut stream = stream.unwrap();
51-
stream.write(b"Hello World\r\n").unwrap();
52-
panic!("Fail here!");
54+
thread::spawn(|| {
55+
let mut stream = stream.unwrap();
56+
stream.write_all(b"Hello World\r\n").unwrap();
57+
panic!("Fail in thread!");
58+
});
59+
panic!("Fail in event loop");
5360
}
61+
62+
Ok(())
5463
}
5564
```

examples/simple.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use bastion::prelude::*;
2+
3+
#[fort::root]
4+
async fn main(_: BastionContext) -> Result<(), ()> {
5+
println!("Running in Bastion runtime!");
6+
Ok(())
7+
}

0 commit comments

Comments
 (0)