Fix readme and add simple example (#7)

* Fix readme and add simple example

* Bump version on readme
This commit is contained in:
Mahmut Bulut 2019-12-10 00:21:19 +01:00 committed by GitHub
parent 65ffbf6305
commit 55a9b4ba20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View File

@ -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(())
}
```

7
examples/simple.rs Normal file
View File

@ -0,0 +1,7 @@
use bastion::prelude::*;
#[fort::root]
async fn main(_: BastionContext) -> Result<(), ()> {
println!("Running in Bastion runtime!");
Ok(())
}