pausable_tokio/lib.rs
1#![allow(
2 clippy::cognitive_complexity,
3 clippy::large_enum_variant,
4 clippy::module_inception,
5 clippy::needless_doctest_main
6)]
7#![warn(
8 missing_debug_implementations,
9 missing_docs,
10 rust_2018_idioms,
11 unreachable_pub
12)]
13#![deny(unused_must_use, unsafe_op_in_unsafe_fn)]
14#![doc(test(
15 no_crate_inject,
16 attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
17))]
18// loom is an internal implementation detail.
19// Do not show "Available on non-loom only" label
20#![cfg_attr(docsrs, doc(auto_cfg(hide(loom))))]
21#![cfg_attr(docsrs, feature(doc_cfg))]
22#![cfg_attr(docsrs, allow(unused_attributes))]
23#![cfg_attr(loom, allow(dead_code, unreachable_pub))]
24#![cfg_attr(windows, allow(rustdoc::broken_intra_doc_links))]
25
26//! `pausable-tokio` is a fork of [`tokio`] that adds a runtime-
27//! controllable pause/resume primitive on its clock. The rest of the
28//! tokio API is unchanged; see
29//! [`Builder::pausable_time`](crate::runtime::Builder::pausable_time)
30//! and the methods on [`Runtime`](crate::runtime::Runtime) (`pause`,
31//! `resume`, `wait_for_resume`, `run_unpausable`, etc.) for the
32//! pausable-specific bits, and the rest of these docs (inherited from
33//! upstream tokio) for everything else.
34//!
35//! ```toml
36//! [dependencies]
37//! tokio = { package = "pausable-tokio", version = "1.52.1", features = ["full"] }
38//! ```
39//!
40//! [`tokio`]: https://docs.rs/tokio
41//!
42//! ----
43//!
44//! A runtime for writing reliable network applications without compromising speed.
45//!
46//! Tokio is an event-driven, non-blocking I/O platform for writing asynchronous
47//! applications with the Rust programming language. At a high level, it
48//! provides a few major components:
49//!
50//! * Tools for [working with asynchronous tasks][tasks], including
51//! [synchronization primitives and channels][sync] and [timeouts, sleeps, and
52//! intervals][time].
53//! * APIs for [performing asynchronous I/O][io], including [TCP and UDP][net] sockets,
54//! [filesystem][fs] operations, and [process] and [signal] management.
55//! * A [runtime] for executing asynchronous code, including a task scheduler,
56//! an I/O driver backed by the operating system's event queue (`epoll`, `kqueue`,
57//! `IOCP`, etc...), and a high performance timer.
58//!
59//! Guide level documentation is found on the [website].
60//!
61//! [tasks]: #working-with-tasks
62//! [sync]: crate::sync
63//! [time]: crate::time
64//! [io]: #asynchronous-io
65//! [net]: crate::net
66//! [fs]: crate::fs
67//! [process]: crate::process
68//! [signal]: crate::signal
69//! [fs]: crate::fs
70//! [runtime]: crate::runtime
71//! [website]: https://tokio.rs/tokio/tutorial
72//!
73//! # A Tour of Tokio
74//!
75//! Tokio consists of a number of modules that provide a range of functionality
76//! essential for implementing asynchronous applications in Rust. In this
77//! section, we will take a brief tour of Tokio, summarizing the major APIs and
78//! their uses.
79//!
80//! The easiest way to get started is to enable all features. Do this by
81//! enabling the `full` feature flag:
82//!
83//! ```toml
84//! tokio = { version = "1", features = ["full"] }
85//! ```
86//!
87//! ### Authoring applications
88//!
89//! Tokio is great for writing applications and most users in this case shouldn't
90//! worry too much about what features they should pick. If you're unsure, we suggest
91//! going with `full` to ensure that you don't run into any road blocks while you're
92//! building your application.
93//!
94//! #### Example
95//!
96//! This example shows the quickest way to get started with Tokio.
97//!
98//! ```toml
99//! tokio = { version = "1", features = ["full"] }
100//! ```
101//!
102//! ### Authoring libraries
103//!
104//! As a library author your goal should be to provide the lightest weight crate
105//! that is based on Tokio. To achieve this you should ensure that you only enable
106//! the features you need. This allows users to pick up your crate without having
107//! to enable unnecessary features.
108//!
109//! #### Example
110//!
111//! This example shows how you may want to import features for a library that just
112//! needs to `tokio::spawn` and use a `TcpStream`.
113//!
114//! ```toml
115//! tokio = { version = "1", features = ["rt", "net"] }
116//! ```
117//!
118//! ## Working With Tasks
119//!
120//! Asynchronous programs in Rust are based around lightweight, non-blocking
121//! units of execution called [_tasks_][tasks]. The [`tokio::task`] module provides
122//! important tools for working with tasks:
123//!
124//! * The [`spawn`] function and [`JoinHandle`] type, for scheduling a new task
125//! on the Tokio runtime and awaiting the output of a spawned task, respectively,
126//! * Functions for [running blocking operations][blocking] in an asynchronous
127//! task context.
128//!
129//! The [`tokio::task`] module is present only when the "rt" feature flag
130//! is enabled.
131//!
132//! [tasks]: task/index.html#what-are-tasks
133//! [`tokio::task`]: crate::task
134//! [`spawn`]: crate::task::spawn()
135//! [`JoinHandle`]: crate::task::JoinHandle
136//! [blocking]: task/index.html#blocking-and-yielding
137//!
138//! The [`tokio::sync`] module contains synchronization primitives to use when
139//! needing to communicate or share data. These include:
140//!
141//! * channels ([`oneshot`], [`mpsc`], [`watch`], and [`broadcast`]), for sending values
142//! between tasks,
143//! * a non-blocking [`Mutex`], for controlling access to a shared, mutable
144//! value,
145//! * an asynchronous [`Barrier`] type, for multiple tasks to synchronize before
146//! beginning a computation.
147//!
148//! The `tokio::sync` module is present only when the "sync" feature flag is
149//! enabled.
150//!
151//! [`tokio::sync`]: crate::sync
152//! [`Mutex`]: crate::sync::Mutex
153//! [`Barrier`]: crate::sync::Barrier
154//! [`oneshot`]: crate::sync::oneshot
155//! [`mpsc`]: crate::sync::mpsc
156//! [`watch`]: crate::sync::watch
157//! [`broadcast`]: crate::sync::broadcast
158//!
159//! The [`tokio::time`] module provides utilities for tracking time and
160//! scheduling work. This includes functions for setting [timeouts][timeout] for
161//! tasks, [sleeping][sleep] work to run in the future, or [repeating an operation at an
162//! interval][interval].
163//!
164//! In order to use `tokio::time`, the "time" feature flag must be enabled.
165//!
166//! [`tokio::time`]: crate::time
167//! [sleep]: crate::time::sleep()
168//! [interval]: crate::time::interval()
169//! [timeout]: crate::time::timeout()
170//!
171//! Finally, Tokio provides a _runtime_ for executing asynchronous tasks. Most
172//! applications can use the [`#[tokio::main]`][main] macro to run their code on the
173//! Tokio runtime. However, this macro provides only basic configuration options. As
174//! an alternative, the [`tokio::runtime`] module provides more powerful APIs for configuring
175//! and managing runtimes. You should use that module if the `#[tokio::main]` macro doesn't
176//! provide the functionality you need.
177//!
178//! Using the runtime requires the "rt" or "rt-multi-thread" feature flags, to
179//! enable the current-thread [single-threaded scheduler][rt] and the [multi-thread
180//! scheduler][rt-multi-thread], respectively. See the [`runtime` module
181//! documentation][rt-features] for details. In addition, the "macros" feature
182//! flag enables the `#[tokio::main]` and `#[tokio::test]` attributes.
183//!
184//! [main]: attr.main.html
185//! [`tokio::runtime`]: crate::runtime
186//! [`Builder`]: crate::runtime::Builder
187//! [`Runtime`]: crate::runtime::Runtime
188//! [rt]: runtime/index.html#current-thread-scheduler
189//! [rt-multi-thread]: runtime/index.html#multi-thread-scheduler
190//! [rt-features]: runtime/index.html#runtime-scheduler
191//!
192//! ## CPU-bound tasks and blocking code
193//!
194//! Tokio is able to concurrently run many tasks on a few threads by repeatedly
195//! swapping the currently running task on each thread. However, this kind of
196//! swapping can only happen at `.await` points, so code that spends a long time
197//! without reaching an `.await` will prevent other tasks from running. To
198//! combat this, Tokio provides two kinds of threads: Core threads and blocking threads.
199//!
200//! The core threads are where all asynchronous code runs, and Tokio will by default
201//! spawn one for each CPU core. You can use the environment variable `TOKIO_WORKER_THREADS`
202//! to override the default value.
203//!
204//! The blocking threads are spawned on demand, can be used to run blocking code
205//! that would otherwise block other tasks from running and are kept alive when
206//! not used for a certain amount of time which can be configured with [`thread_keep_alive`].
207//! Since it is not possible for Tokio to swap out blocking tasks, like it
208//! can do with asynchronous code, the upper limit on the number of blocking
209//! threads is very large. These limits can be configured on the [`Builder`].
210//!
211//! To spawn a blocking task, you should use the [`spawn_blocking`] function.
212//!
213//! [`Builder`]: crate::runtime::Builder
214//! [`spawn_blocking`]: crate::task::spawn_blocking()
215//! [`thread_keep_alive`]: crate::runtime::Builder::thread_keep_alive()
216//!
217//! ```
218//! # #[cfg(not(target_family = "wasm"))]
219//! # {
220//! #[tokio::main]
221//! async fn main() {
222//! // This is running on a core thread.
223//!
224//! let blocking_task = tokio::task::spawn_blocking(|| {
225//! // This is running on a blocking thread.
226//! // Blocking here is ok.
227//! });
228//!
229//! // We can wait for the blocking task like this:
230//! // If the blocking task panics, the unwrap below will propagate the
231//! // panic.
232//! blocking_task.await.unwrap();
233//! }
234//! # }
235//! ```
236//!
237//! If your code is CPU-bound and you wish to limit the number of threads used
238//! to run it, you should use a separate thread pool dedicated to CPU bound tasks.
239//! For example, you could consider using the [rayon] library for CPU-bound
240//! tasks. It is also possible to create an extra Tokio runtime dedicated to
241//! CPU-bound tasks, but if you do this, you should be careful that the extra
242//! runtime runs _only_ CPU-bound tasks, as IO-bound tasks on that runtime
243//! will behave poorly.
244//!
245//! Hint: If using rayon, you can use a [`oneshot`] channel to send the result back
246//! to Tokio when the rayon task finishes.
247//!
248//! [rayon]: https://docs.rs/rayon
249//! [`oneshot`]: crate::sync::oneshot
250//!
251//! ## Asynchronous IO
252//!
253//! As well as scheduling and running tasks, Tokio provides everything you need
254//! to perform input and output asynchronously.
255//!
256//! The [`tokio::io`] module provides Tokio's asynchronous core I/O primitives,
257//! the [`AsyncRead`], [`AsyncWrite`], and [`AsyncBufRead`] traits. In addition,
258//! when the "io-util" feature flag is enabled, it also provides combinators and
259//! functions for working with these traits, forming as an asynchronous
260//! counterpart to [`std::io`].
261//!
262//! Tokio also includes APIs for performing various kinds of I/O and interacting
263//! with the operating system asynchronously. These include:
264//!
265//! * [`tokio::net`], which contains non-blocking versions of [TCP], [UDP], and
266//! [Unix Domain Sockets][UDS] (enabled by the "net" feature flag),
267//! * [`tokio::fs`], similar to [`std::fs`] but for performing filesystem I/O
268//! asynchronously (enabled by the "fs" feature flag),
269//! * [`tokio::signal`], for asynchronously handling Unix and Windows OS signals
270//! (enabled by the "signal" feature flag),
271//! * [`tokio::process`], for spawning and managing child processes (enabled by
272//! the "process" feature flag).
273//!
274//! [`tokio::io`]: crate::io
275//! [`AsyncRead`]: crate::io::AsyncRead
276//! [`AsyncWrite`]: crate::io::AsyncWrite
277//! [`AsyncBufRead`]: crate::io::AsyncBufRead
278//! [`std::io`]: std::io
279//! [`tokio::net`]: crate::net
280//! [TCP]: crate::net::tcp
281//! [UDP]: crate::net::UdpSocket
282//! [UDS]: crate::net::unix
283//! [`tokio::fs`]: crate::fs
284//! [`std::fs`]: std::fs
285//! [`tokio::signal`]: crate::signal
286//! [`tokio::process`]: crate::process
287//!
288//! # Examples
289//!
290//! A simple TCP echo server:
291//!
292//! ```no_run
293//! # #[cfg(not(target_family = "wasm"))]
294//! # {
295//! use tokio::net::TcpListener;
296//! use tokio::io::{AsyncReadExt, AsyncWriteExt};
297//!
298//! #[tokio::main]
299//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
300//! let listener = TcpListener::bind("127.0.0.1:8080").await?;
301//!
302//! loop {
303//! let (mut socket, _) = listener.accept().await?;
304//!
305//! tokio::spawn(async move {
306//! let mut buf = [0; 1024];
307//!
308//! // In a loop, read data from the socket and write the data back.
309//! loop {
310//! let n = match socket.read(&mut buf).await {
311//! // socket closed
312//! Ok(0) => return,
313//! Ok(n) => n,
314//! Err(e) => {
315//! eprintln!("failed to read from socket; err = {:?}", e);
316//! return;
317//! }
318//! };
319//!
320//! // Write the data back
321//! if let Err(e) = socket.write_all(&buf[0..n]).await {
322//! eprintln!("failed to write to socket; err = {:?}", e);
323//! return;
324//! }
325//! }
326//! });
327//! }
328//! }
329//! # }
330//! ```
331//!
332//! # Feature flags
333//!
334//! Tokio uses a set of [feature flags] to reduce the amount of compiled code. It
335//! is possible to just enable certain features over others. By default, Tokio
336//! does not enable any features but allows one to enable a subset for their use
337//! case. Below is a list of the available feature flags. You may also notice
338//! above each function, struct and trait there is listed one or more feature flags
339//! that are required for that item to be used. If you are new to Tokio it is
340//! recommended that you use the `full` feature flag which will enable all public APIs.
341//! Beware though that this will pull in many extra dependencies that you may not
342//! need.
343//!
344//! - `full`: Enables all features listed below except `test-util` and unstable features.
345//! - `rt`: Enables `tokio::spawn`, the current-thread scheduler,
346//! and non-scheduler utilities.
347//! - `rt-multi-thread`: Enables the heavier, multi-threaded, work-stealing scheduler.
348//! - `io-util`: Enables the IO based `Ext` traits.
349//! - `io-std`: Enable `Stdout`, `Stdin` and `Stderr` types.
350//! - `net`: Enables `tokio::net` types such as `TcpStream`, `UnixStream` and
351//! `UdpSocket`, as well as (on Unix-like systems) `AsyncFd` and (on
352//! FreeBSD) `PollAio`.
353//! - `time`: Enables `tokio::time` types and allows the schedulers to enable
354//! the built-in timer.
355//! - `process`: Enables `tokio::process` types.
356//! - `macros`: Enables `#[tokio::main]` and `#[tokio::test]` macros.
357//! - `sync`: Enables all `tokio::sync` types.
358//! - `signal`: Enables all `tokio::signal` types.
359//! - `fs`: Enables `tokio::fs` types.
360//! - `test-util`: Enables testing based infrastructure for the Tokio runtime.
361//! - `parking_lot`: As a potential optimization, use the [`parking_lot`] crate's
362//! synchronization primitives internally. Also, this
363//! dependency is necessary to construct some of our primitives
364//! in a `const` context. `MSRV` may increase according to the
365//! [`parking_lot`] release in use.
366//!
367//! _Note: `AsyncRead` and `AsyncWrite` traits do not require any features and are
368//! always available._
369//!
370//! ## Unstable features
371//!
372//! Some feature flags are only available when specifying the `tokio_unstable` flag:
373//!
374//! - `tracing`: Enables tracing events.
375//! - `io-uring`: Enables `io-uring` (Linux only).
376//! - `taskdump`: Enables `taskdump` (Linux only).
377//!
378//! Likewise, this flag enables access to unstable APIs.
379//!
380//! This flag enables **unstable** features. The public API of these features
381//! may break in 1.x releases. To enable these features, the `--cfg
382//! tokio_unstable` argument must be passed to `rustc` when compiling. This
383//! serves to explicitly opt-in to features which may break semver conventions,
384//! since Cargo [does not yet directly support such opt-ins][unstable features].
385//!
386//! You can specify it in your project's `.cargo/config.toml` file:
387//!
388//! ```toml
389//! [build]
390//! rustflags = ["--cfg", "tokio_unstable"]
391//! ```
392//!
393//! <div class="warning">
394//! The <code>[build]</code> section does <strong>not</strong> go in a
395//! <code>Cargo.toml</code> file. Instead it must be placed in the Cargo config
396//! file <code>.cargo/config.toml</code>.
397//! </div>
398//!
399//! Alternatively, you can specify it with an environment variable:
400//!
401//! ```sh
402//! ## Many *nix shells:
403//! export RUSTFLAGS="--cfg tokio_unstable"
404//! cargo build
405//! ```
406//!
407//! ```powershell
408//! ## Windows PowerShell:
409//! $Env:RUSTFLAGS="--cfg tokio_unstable"
410//! cargo build
411//! ```
412//!
413//! [unstable features]: https://internals.rust-lang.org/t/feature-request-unstable-opt-in-non-transitive-crate-features/16193#why-not-a-crate-feature-2
414//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
415//!
416//! # Supported platforms
417//!
418//! Tokio currently guarantees support for the following platforms:
419//!
420//! * Linux
421//! * Windows
422//! * Android (API level 21)
423//! * macOS
424//! * iOS
425//! * FreeBSD
426//!
427//! Tokio will continue to support these platforms in the future. However,
428//! future releases may change requirements such as the minimum required libc
429//! version on Linux, the API level on Android, or the supported FreeBSD
430//! release.
431//!
432//! Beyond the above platforms, Tokio is intended to work on all platforms
433//! supported by the mio crate. You can find a longer list [in mio's
434//! documentation][mio-supported]. However, these additional platforms may
435//! become unsupported in the future.
436//!
437//! Note that Wine is considered to be a different platform from Windows. See
438//! mio's documentation for more information on Wine support.
439//!
440//! [mio-supported]: https://crates.io/crates/mio#platforms
441//!
442//! ## `WASM` support
443//!
444//! Tokio has some limited support for the `WASM` platform. Without the
445//! `tokio_unstable` flag, the following features are supported:
446//!
447//! * `sync`
448//! * `macros`
449//! * `io-util`
450//! * `rt`
451//! * `time`
452//!
453//! Enabling any other feature (including `full`) will cause a compilation
454//! failure.
455//!
456//! The `time` module will only work on `WASM` platforms that have support for
457//! timers (e.g. wasm32-wasi). The timing functions will panic if used on a `WASM`
458//! platform that does not support timers.
459//!
460//! Note also that if the runtime becomes indefinitely idle, it will panic
461//! immediately instead of blocking forever. On platforms that don't support
462//! time, this means that the runtime can never be idle in any way.
463//!
464//! ## Unstable `WASM` support
465//!
466//! Tokio also has unstable support for some additional `WASM` features. This
467//! requires the use of the `tokio_unstable` flag.
468//!
469//! Using this flag enables the use of `tokio::net` on the wasm32-wasi target.
470//! However, not all methods are available on the networking types as `WASI`
471//! currently does not support the creation of new sockets from within `WASM`.
472//! Because of this, sockets must currently be created via the `FromRawFd`
473//! trait.
474
475// Test that pointer width is compatible. This asserts that e.g. usize is at
476// least 32 bits, which a lot of components in Tokio currently assumes.
477//
478// TODO: improve once we have MSRV access to const eval to make more flexible.
479#[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64")))]
480compile_error! {
481 "Tokio requires the platform pointer width to be at least 32 bits"
482}
483
484#[cfg(all(
485 not(tokio_unstable),
486 target_family = "wasm",
487 any(
488 feature = "fs",
489 feature = "io-std",
490 feature = "net",
491 feature = "process",
492 feature = "rt-multi-thread",
493 feature = "signal"
494 )
495))]
496compile_error!("Only features sync,macros,io-util,rt,time are supported on wasm.");
497
498#[cfg(all(not(tokio_unstable), feature = "io-uring"))]
499compile_error!("The `io-uring` feature requires `--cfg tokio_unstable`.");
500
501#[cfg(all(not(tokio_unstable), feature = "taskdump"))]
502compile_error!("The `taskdump` feature requires `--cfg tokio_unstable`.");
503
504#[cfg(all(
505 feature = "taskdump",
506 not(doc),
507 not(all(
508 target_os = "linux",
509 any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
510 ))
511))]
512compile_error!(
513 "The `taskdump` feature is only currently supported on \
514linux, on `aarch64`, `x86` and `x86_64`."
515);
516
517// Includes re-exports used by macros.
518//
519// This module is not intended to be part of the public API. In general, any
520// `doc(hidden)` code is not part of Tokio's public and stable API.
521#[macro_use]
522#[doc(hidden)]
523pub mod macros;
524
525cfg_fs! {
526 pub mod fs;
527}
528
529mod future;
530
531pub mod io;
532pub mod net;
533
534mod loom;
535
536cfg_process! {
537 pub mod process;
538}
539
540#[cfg(any(
541 feature = "fs",
542 feature = "io-std",
543 feature = "net",
544 all(windows, feature = "process"),
545))]
546mod blocking;
547
548cfg_rt! {
549 pub mod runtime;
550}
551cfg_not_rt! {
552 pub(crate) mod runtime;
553}
554
555cfg_signal! {
556 pub mod signal;
557}
558
559cfg_signal_internal! {
560 #[cfg(not(feature = "signal"))]
561 #[allow(dead_code)]
562 #[allow(unreachable_pub)]
563 pub(crate) mod signal;
564}
565
566cfg_sync! {
567 pub mod sync;
568}
569cfg_not_sync! {
570 mod sync;
571}
572
573// Currently, task module does not expose any public API outside `rt`
574// feature, so we mark it in the docs. This happens only to docs to
575// avoid introducing breaking changes by restricting the visibility
576// of the task module.
577#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
578pub mod task;
579cfg_rt! {
580 pub use task::spawn;
581}
582
583cfg_time! {
584 pub mod time;
585}
586
587mod trace {
588 cfg_taskdump! {
589 pub(crate) use crate::runtime::task::trace::trace_leaf;
590 }
591
592 cfg_not_taskdump! {
593 #[inline(always)]
594 #[allow(dead_code)]
595 pub(crate) fn trace_leaf(_: &mut std::task::Context<'_>) -> std::task::Poll<()> {
596 std::task::Poll::Ready(())
597 }
598 }
599
600 #[cfg_attr(not(feature = "sync"), allow(dead_code))]
601 pub(crate) async fn async_trace_leaf() {
602 std::future::poll_fn(trace_leaf).await
603 }
604}
605
606mod util;
607
608/// Due to the `Stream` trait's inclusion in `std` landing later than Tokio's 1.0
609/// release, most of the Tokio stream utilities have been moved into the [`tokio-stream`]
610/// crate.
611///
612/// # Why was `Stream` not included in Tokio 1.0?
613///
614/// Originally, we had planned to ship Tokio 1.0 with a stable `Stream` type
615/// but unfortunately the [RFC] had not been merged in time for `Stream` to
616/// reach `std` on a stable compiler in time for the 1.0 release of Tokio. For
617/// this reason, the team has decided to move all `Stream` based utilities to
618/// the [`tokio-stream`] crate. While this is not ideal, once `Stream` has made
619/// it into the standard library and the `MSRV` period has passed, we will implement
620/// stream for our different types.
621///
622/// While this may seem unfortunate, not all is lost as you can get much of the
623/// `Stream` support with `async/await` and `while let` loops. It is also possible
624/// to create a `impl Stream` from `async fn` using the [`async-stream`] crate.
625///
626/// [`tokio-stream`]: https://docs.rs/tokio-stream
627/// [`async-stream`]: https://docs.rs/async-stream
628/// [RFC]: https://github.com/rust-lang/rfcs/pull/2996
629///
630/// # Example
631///
632/// Convert a [`sync::mpsc::Receiver`] to an `impl Stream`.
633///
634/// ```rust,no_run
635/// use tokio::sync::mpsc;
636///
637/// let (tx, mut rx) = mpsc::channel::<usize>(16);
638///
639/// let stream = async_stream::stream! {
640/// while let Some(item) = rx.recv().await {
641/// yield item;
642/// }
643/// };
644/// ```
645pub mod stream {}
646
647// local re-exports of platform specific things, allowing for decent
648// documentation to be shimmed in on docs.rs
649
650#[cfg(all(docsrs, unix))]
651pub mod doc;
652
653#[cfg(any(feature = "net", feature = "fs"))]
654#[cfg(all(docsrs, unix))]
655#[allow(unused)]
656pub(crate) use self::doc::os;
657
658#[cfg(not(all(docsrs, unix)))]
659#[allow(unused)]
660pub(crate) use std::os;
661
662cfg_macros! {
663 /// Implementation detail of the `select!` macro. This macro is **not**
664 /// intended to be used as part of the public API and is permitted to
665 /// change.
666 #[doc(hidden)]
667 pub use tokio_macros::select_priv_declare_output_enum;
668
669 /// Implementation detail of the `select!` macro. This macro is **not**
670 /// intended to be used as part of the public API and is permitted to
671 /// change.
672 #[doc(hidden)]
673 pub use tokio_macros::select_priv_clean_pattern;
674
675 cfg_rt! {
676 #[cfg(feature = "rt-multi-thread")]
677 #[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
678 #[doc(inline)]
679 pub use tokio_macros::main;
680
681 #[cfg(feature = "rt-multi-thread")]
682 #[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
683 #[doc(inline)]
684 pub use tokio_macros::test;
685
686 cfg_not_rt_multi_thread! {
687 #[doc(inline)]
688 pub use tokio_macros::main_rt as main;
689
690 #[doc(inline)]
691 pub use tokio_macros::test_rt as test;
692 }
693 }
694
695 // Always fail if rt is not enabled.
696 cfg_not_rt! {
697 #[doc(inline)]
698 pub use tokio_macros::main_fail as main;
699
700 #[doc(inline)]
701 pub use tokio_macros::test_fail as test;
702 }
703}
704
705// TODO: rm
706#[cfg(feature = "io-util")]
707#[cfg(test)]
708fn is_unpin<T: Unpin>() {}
709
710/// fuzz test (`fuzz_linked_list`)
711#[cfg(fuzzing)]
712pub mod fuzz;