mirror of https://github.com/bastion-rs/fort
Fix readme and add simple example (#7)
* Fix readme and add simple example * Bump version on readme
This commit is contained in:
parent
65ffbf6305
commit
55a9b4ba20
29
README.md
29
README.md
|
@ -5,22 +5,23 @@ Fort is proc macro attribute crate for Bastion.
|
|||
## Usage
|
||||
```toml
|
||||
[dependencies]
|
||||
fort = "0.2"
|
||||
fort = "0.3"
|
||||
bastion = "0.3.*"
|
||||
```
|
||||
|
||||
You can directly use fort to load work onto the root supervisor with:
|
||||
```rust
|
||||
#[fort::root]
|
||||
fn main() {
|
||||
async fn main(_: BastionContext) -> Result<(), ()> {
|
||||
println!("Running in Bastion runtime!");
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
Make your program fault-tolerant with `fort`:
|
||||
```rust
|
||||
#[fort::root]
|
||||
fn main() {
|
||||
async fn main(_: BastionContext) -> Result<(), ()> {
|
||||
loop {
|
||||
println!("Undying main!");
|
||||
panic!("Error")
|
||||
|
@ -30,9 +31,12 @@ fn main() {
|
|||
|
||||
You want to spawn multiple process
|
||||
```rust
|
||||
#[fort::root(redundancy = 3)]
|
||||
fn main() {
|
||||
println!("Running in Bastion runtime!");
|
||||
#[fort::root(redundancy = 10)]
|
||||
async fn main(_: BastionContext) -> Result<(), ()> {
|
||||
loop {
|
||||
println!("Undying main!");
|
||||
panic!("Error")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -43,13 +47,18 @@ use std::io::Write;
|
|||
use std::net::TcpListener;
|
||||
|
||||
#[fort::root]
|
||||
fn main() {
|
||||
async fn main(_: BastionContext) -> Result<(), ()> {
|
||||
let listener = TcpListener::bind("127.0.0.1:2278").unwrap();
|
||||
println!("TCP server started at 127.0.0.1:2278");
|
||||
for stream in listener.incoming() {
|
||||
let mut stream = stream.unwrap();
|
||||
stream.write(b"Hello World\r\n").unwrap();
|
||||
panic!("Fail here!");
|
||||
thread::spawn(|| {
|
||||
let mut stream = stream.unwrap();
|
||||
stream.write_all(b"Hello World\r\n").unwrap();
|
||||
panic!("Fail in thread!");
|
||||
});
|
||||
panic!("Fail in event loop");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
use bastion::prelude::*;
|
||||
|
||||
#[fort::root]
|
||||
async fn main(_: BastionContext) -> Result<(), ()> {
|
||||
println!("Running in Bastion runtime!");
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue