1 unstable release

0.1.0 Dec 2, 2021

#58 in #worker-thread

Download history 603/week @ 2024-05-22 794/week @ 2024-05-29 563/week @ 2024-06-05 1136/week @ 2024-06-12 758/week @ 2024-06-19 720/week @ 2024-06-26 784/week @ 2024-07-03 696/week @ 2024-07-10 946/week @ 2024-07-17 696/week @ 2024-07-24 1734/week @ 2024-07-31 1693/week @ 2024-08-07 1090/week @ 2024-08-14 1031/week @ 2024-08-21 737/week @ 2024-08-28 528/week @ 2024-09-04

3,442 downloads per month
Used in tokio_env

Apache-2.0

3KB

tokio-env

A configuration library for convenient setup of the tokio runtime.

Configuration

All configuration is made vie environmental variables. The following variables are supported:

  • TOKIO_ENABLE_ALL Whether to enable all types of thread pools. Defaults to true.
  • TOKIO_BLOCKING_THREADS The amount of blocking threads to use.
  • TOKIO_WORKER_THREADS The amount of worker threads to use.
  • TOKIO_THREAD_STACK_SIZE The size of the stack for the created threads.
  • TOKIO_THREAD_NAME The name for the created thread pool(s).

If the environment variable is not provided, it will fall back to the tokio defaults, except for the TOKIO_ENABLE_ALL which defaults to true.

So an empty configuration unfolds like this:

tokio::runtime::Builder::new_multi_thread()
    .enable_all()
    .map(|runtime| runtime.block_on(fun));

Usage

Usage of this library could look like this:

fn main() {
    println!("Initializing tokio runtime...");
    let exit_code = tokio_env::start_with(run)
        .expect("Failed to start tokio runtime!");
    println!("Tokio runtime exited with code: {}", exit_code)
}

async fn run() -> i32 {
    println!("Program started!");
    // Your async logic here
    0
}

But... why?

I'm tired of writing the same boilerplate code over and over again, so I made it a one-liner!

Dependencies

~1.5MB
~36K SLoC