pub struct Reactor { /* private fields */ }Expand description
The executor that owns the reactor — the capability a reactor-bound task is spawned through.
Hold one and you may spawn a future that opens a tokio::net socket, waits
on tokio::time, or installs a signal handler. The counterpart is
spawn_background, which needs no capability because the executor it
lands on is process-global — and, for the same reason, has no reactor.
§Where one comes from
Reactor::current mints one from the runtime entered on the calling
thread, and returns None rather than panicking when there is none.
Everything else receives one: the IOC and the CA/PVA servers and clients
capture it once on their own setup path and hand &Reactor down to the
tasks they start. BlockingBridge::reactor is the third source, for a
blocking thread the runtime is not entered on.
Implementations§
Source§impl Reactor
impl Reactor
Sourcepub fn current() -> Option<Self>
pub fn current() -> Option<Self>
The runtime entered on this thread, or None when there is none.
Deliberately not a panicking constructor: the ambient spawn this
replaces panicked from inside itself, which is exactly the failure the
capability exists to move into the type. A caller that genuinely cannot
continue without one writes its own expect, which names the reason and
can be found by a census.
Sourcepub fn spawn<F>(&self, future: F) -> TaskHandle<F::Output>
pub fn spawn<F>(&self, future: F) -> TaskHandle<F::Output>
Spawn a reactor-bound future.
Works from any thread, including one the runtime is not entered on —
the handle carries the runtime, where tokio::spawn read a
thread-local.
Sourcepub fn spawn_blocking<F, R>(&self, f: F) -> TaskHandle<R>
pub fn spawn_blocking<F, R>(&self, f: F) -> TaskHandle<R>
Run a blocking closure on the runtime’s blocking pool.