zlink_zruntime/lib.rs
1#![doc(
2 html_logo_url = "https://raw.githubusercontent.com/z-galaxy/zlink/3660d731d7de8f60c8d82e122b3ece15617185e4/data/logo.png"
3)]
4#![deny(
5 missing_debug_implementations,
6 nonstandard_style,
7 rust_2018_idioms,
8 missing_docs
9)]
10#![warn(unreachable_pub)]
11#![cfg_attr(not(doctest), doc = include_str!("../README.md"))]
12
13pub(crate) use zlink_core::*;
14pub mod byte_stream;
15#[cfg(feature = "server")]
16pub mod notified;
17pub mod unix;
18
19/// Runs a future to completion on the calling thread, together with zruntime.
20///
21/// This is for a program that has no async runtime to poll zlink's futures with: put the async
22/// code in one call to it, and the call blocks the thread until the future completes.
23///
24/// The sockets that [`unix`] makes inside the call are on the runtime of the calling thread:
25/// between polls of the future, the thread runs their I/O, so their traffic needs no other thread.
26/// They work under any other executor as well: where no call to this function runs their I/O, a
27/// helper thread of zruntime does. `connect_local` and `bind_local` instead require a running
28/// `LocalRuntime`.
29///
30/// The future must not block the thread to wait for the sockets, for example by waiting
31/// synchronously for a reply: their I/O runs on this same thread, between polls of the future, so
32/// such a wait never ends.
33///
34/// # Panics
35///
36/// Panics if the calling thread is running zruntime already, as it is inside the future of another
37/// call to this function: the inner call would wait for its own thread. Do not call it from a task
38/// of another executor either: it blocks that executor's thread until the future completes, which
39/// deadlocks if the future needs that thread.
40pub fn block_on<F>(future: F) -> F::Output
41where
42 F: Future,
43{
44 zruntime::block_on(future)
45}