Go to file
Mahmut Bulut 47078b276c (cargo-release) start next development iteration 0.4.1-alpha.0 2020-12-21 12:01:02 +01:00
.github Add usage and fix dependency problems 2019-10-06 13:25:44 +02:00
examples Fix readme and add simple example (#7) 2019-12-10 00:21:19 +01:00
src Remove redundant `extern crate` (#10) 2020-10-07 18:11:36 +02:00
.gitignore Get retry times 2019-10-25 15:01:23 +07:00
Cargo.toml (cargo-release) start next development iteration 0.4.1-alpha.0 2020-12-21 12:01:02 +01:00
LICENSE-APACHE
LICENSE-MIT
README.md Update fort 2020-12-21 11:57:32 +01:00

README.md

Fort

Fort is proc macro attribute crate for Bastion.

Usage

[dependencies]
fort = "0.4"
bastion = "0.4"

You can directly use fort to load work onto the root supervisor with:

#[fort::root]
async fn main(_: BastionContext) -> Result<(), ()> {
    println!("Running in Bastion runtime!");
    Ok(())
}

Make your program fault-tolerant with fort:

#[fort::root]
async fn main(_: BastionContext) -> Result<(), ()> {
    loop {
        println!("Undying main!");
        panic!("Error")
    }
}

You want to spawn multiple process

#[fort::root(redundancy = 10)]
async fn main(_: BastionContext) -> Result<(), ()> {
    loop {
        println!("Undying main!");
        panic!("Error")
    }
}

Example TCP Server

use std::io::Write;
use std::net::TcpListener;

#[fort::root]
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() {
        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(())
}