@@ -5,22 +5,23 @@ Fort is proc macro attribute crate for Bastion.
5
5
## Usage
6
6
``` toml
7
7
[dependencies ]
8
- fort = " 0.2 "
8
+ fort = " 0.3 "
9
9
bastion = " 0.3.*"
10
10
```
11
11
12
12
You can directly use fort to load work onto the root supervisor with:
13
13
``` rust
14
14
#[fort:: root]
15
- fn main () {
15
+ async fn main (_ : BastionContext ) -> Result <(), ()> {
16
16
println! (" Running in Bastion runtime!" );
17
+ Ok (())
17
18
}
18
19
```
19
20
20
21
Make your program fault-tolerant with ` fort ` :
21
22
``` rust
22
23
#[fort:: root]
23
- fn main () {
24
+ async fn main (_ : BastionContext ) -> Result <(), ()> {
24
25
loop {
25
26
println! (" Undying main!" );
26
27
panic! (" Error" )
@@ -30,9 +31,12 @@ fn main() {
30
31
31
32
You want to spawn multiple process
32
33
``` 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
+ }
36
40
}
37
41
```
38
42
@@ -43,13 +47,18 @@ use std::io::Write;
43
47
use std :: net :: TcpListener ;
44
48
45
49
#[fort:: root]
46
- fn main () {
50
+ async fn main (_ : BastionContext ) -> Result <(), ()> {
47
51
let listener = TcpListener :: bind (" 127.0.0.1:2278" ). unwrap ();
48
52
println! (" TCP server started at 127.0.0.1:2278" );
49
53
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" );
53
60
}
61
+
62
+ Ok (())
54
63
}
55
64
```
0 commit comments