Crate abscissa_tokio

source ·
Expand description

Support for launching Tokio runtimes within Abscissa applications.


Where normally you’d use something like the tokio::main macro to launch the Tokio runtime, in Abscissa the framework is launched by calling abscissa_core::boot from your application’s main().

This means Abscissa applications need a slightly different convention for starting the Tokio runtime, and ideally one which allows all application subcomponents to register themselves before the runtime is started.

This crate handles instantiating the Tokio runtime as an Abscissa Component, allowing other application components to express they have a Tokio dependency so Abscissa can inject the Tokio component as a dependency.


Defining Abscissa components that depends on Tokio

To register an Abscissa component with the Tokio runtime, add TokioComponent as a dependency to be injected when the runtime is available:

use abscissa_core::{Component, FrameworkError};
use abscissa_tokio::TokioComponent;

#[derive(Component, Debug)]
#[component(inject = "init_tokio(abscissa_tokio::TokioComponent)")]
pub struct MyComponent {}

impl MyComponent {
    pub fn new() -> Result<Self, FrameworkError> {
        Ok(Self {})

    /// Called automatically after `TokioComponent` is initialized
    pub fn init_tokio(&mut self, tokio_cmp: &TokioComponent) -> Result<(), FrameworkError> {
        // Register with the Tokio runtime here, e.g.:
        // `tokio_cmp.runtime()?.spawn(async { ... });`

Add TokioComponent to your Abscissa application

Inside of your app’s src/, find the register_components method and add TokioComponent:

use abscissa_tokio::TokioComponent;

fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> {
    let mut components = self.framework_components(command)?;

    // Create `TokioComponent` and add it to your app's components here:


Inside of the Runnable for one of your application’s subcommands, call abscissa_tokio::run with a provided Future to launch the Tokio runtime:

use crate::application::APP;

impl Runnable for StartCmd {
   fn run(&self) {
       abscissa_tokio::run(&APP, async {
           println!("now running inside the Tokio runtime");


pub use tokio;


Component which manages initialization of a Tokio runtime within the Abscissa application lifecycle.


Run a Future on the Runtime for the provided Application.
Run a Future on the Runtime with the additional functionality of the actix runtime for the provided Application.