requiem_rt/
lib.rs

1//! A runtime implementation that runs everything on the current thread.
2#![deny(rust_2018_idioms, warnings)]
3#![allow(clippy::type_complexity)]
4
5#[cfg(not(test))] // Work around for rust-lang/rust#62127
6pub use requiem_macros::{main, test};
7
8mod arbiter;
9mod builder;
10mod runtime;
11mod system;
12
13pub use self::arbiter::Arbiter;
14pub use self::builder::{Builder, SystemRunner};
15pub use self::runtime::Runtime;
16pub use self::system::System;
17
18#[doc(hidden)]
19pub use requiem_threadpool as blocking;
20
21/// Spawns a future on the current arbiter.
22///
23/// # Panics
24///
25/// This function panics if actix system is not running.
26pub fn spawn<F>(f: F)
27where
28    F: futures::Future<Output = ()> + 'static,
29{
30    if !System::is_set() {
31        panic!("System is not running");
32    }
33
34    Arbiter::spawn(f);
35}
36
37/// Asynchronous signal handling
38pub mod signal {
39    #[cfg(unix)]
40    pub mod unix {
41        pub use tokio::signal::unix::*;
42    }
43    pub use tokio::signal::ctrl_c;
44}
45
46/// TCP/UDP/Unix bindings
47pub mod net {
48    pub use tokio::net::UdpSocket;
49    pub use tokio::net::{TcpListener, TcpStream};
50
51    #[cfg(unix)]
52    mod unix {
53        pub use tokio::net::{UnixDatagram, UnixListener, UnixStream};
54    }
55
56    #[cfg(unix)]
57    pub use self::unix::*;
58}
59
60/// Utilities for tracking time.
61pub mod time {
62    pub use tokio::time::Instant;
63    pub use tokio::time::{delay_for, delay_until, Delay};
64    pub use tokio::time::{interval, interval_at, Interval};
65    pub use tokio::time::{timeout, Timeout};
66}