Crate actix_rt[][src]

Tokio-based single-thread async runtime for the Actix ecosystem.

In most parts of the the Actix ecosystem, it has been chosen to use !Send futures. For this reason, a single-threaded runtime is appropriate since it is guaranteed that futures will not be moved between threads. This can result in small performance improvements over cases where atomics would otherwise be needed.

To achieve similar performance to multi-threaded, work-stealing runtimes, applications using actix-rt will create multiple, mostly disconnected, single-threaded runtimes. This approach has good performance characteristics for workloads where the majority of tasks have similar runtime expense.

The disadvantage is that idle threads will not steal work from very busy, stuck or otherwise backlogged threads. Tasks that are disproportionately expensive should be offloaded to the blocking thread-pool using task::spawn_blocking.

Examples

use std::sync::mpsc;
use actix_rt::{Arbiter, System};

let _ = System::new();

let (tx, rx) = mpsc::channel::<u32>();

let arbiter = Arbiter::new();
arbiter.spawn_fn(move || tx.send(42).unwrap());

let num = rx.recv().unwrap();
assert_eq!(num, 42);

arbiter.stop();
arbiter.join().unwrap();

Modules

net

TCP/UDP/Unix bindings (Tokio re-exports).

signal

Asynchronous signal handling (Tokio re-exports).

task

Task management (Tokio re-exports).

time

Utilities for tracking time (Tokio re-exports).

Structs

Arbiter

An Arbiter represents a thread that provides an asynchronous execution environment for futures and functions.

ArbiterHandle

A handle for sending spawn and stop messages to an Arbiter.

Runtime

A single-threaded runtime based on Tokio's "current thread" runtime.

System

A manager for a per-thread distributed async runtime.

SystemRunner

Runner that keeps a System's event loop alive until stop message is received.

Functions

spawn

Spawns a future on the current thread.

Attribute Macros

main

Marks async function to be executed by actix system.

test

Marks async test function to be executed by actix runtime.