aboutsummaryrefslogtreecommitdiff
path: root/src/future
diff options
context:
space:
mode:
Diffstat (limited to 'src/future')
-rw-r--r--src/future/block_on.rs15
-rw-r--r--src/future/mod.rs23
-rw-r--r--src/future/pending.rs44
-rw-r--r--src/future/poll_fn.rs2
-rw-r--r--src/future/try_join.rs2
5 files changed, 34 insertions, 52 deletions
diff --git a/src/future/block_on.rs b/src/future/block_on.rs
new file mode 100644
index 0000000..91f9cc0
--- /dev/null
+++ b/src/future/block_on.rs
@@ -0,0 +1,15 @@
+use std::future::Future;
+
+cfg_rt! {
+ pub(crate) fn block_on<F: Future>(f: F) -> F::Output {
+ let mut e = crate::runtime::enter::enter(false);
+ e.block_on(f).unwrap()
+ }
+}
+
+cfg_not_rt! {
+ pub(crate) fn block_on<F: Future>(f: F) -> F::Output {
+ let mut park = crate::park::thread::CachedParkThread::new();
+ park.block_on(f).unwrap()
+ }
+}
diff --git a/src/future/mod.rs b/src/future/mod.rs
index 770753f..f7d93c9 100644
--- a/src/future/mod.rs
+++ b/src/future/mod.rs
@@ -1,15 +1,24 @@
-#![allow(unused_imports, dead_code)]
+#![cfg_attr(not(feature = "macros"), allow(unreachable_pub))]
//! Asynchronous values.
-mod maybe_done;
-pub use maybe_done::{maybe_done, MaybeDone};
+#[cfg(any(feature = "macros", feature = "process"))]
+pub(crate) mod maybe_done;
mod poll_fn;
pub use poll_fn::poll_fn;
-mod ready;
-pub(crate) use ready::{ok, Ready};
+cfg_not_loom! {
+ mod ready;
+ pub(crate) use ready::{ok, Ready};
+}
-mod try_join;
-pub(crate) use try_join::try_join3;
+cfg_process! {
+ mod try_join;
+ pub(crate) use try_join::try_join3;
+}
+
+cfg_sync! {
+ mod block_on;
+ pub(crate) use block_on::block_on;
+}
diff --git a/src/future/pending.rs b/src/future/pending.rs
deleted file mode 100644
index 287e836..0000000
--- a/src/future/pending.rs
+++ /dev/null
@@ -1,44 +0,0 @@
-use sdt::pin::Pin;
-use std::future::Future;
-use std::marker;
-use std::task::{Context, Poll};
-
-/// Future for the [`pending()`] function.
-#[derive(Debug)]
-#[must_use = "futures do nothing unless you `.await` or poll them"]
-struct Pending<T> {
- _data: marker::PhantomData<T>,
-}
-
-/// Creates a future which never resolves, representing a computation that never
-/// finishes.
-///
-/// The returned future will forever return [`Poll::Pending`].
-///
-/// # Examples
-///
-/// ```no_run
-/// use tokio::future;
-///
-/// #[tokio::main]
-/// async fn main {
-/// future::pending().await;
-/// unreachable!();
-/// }
-/// ```
-pub async fn pending() -> ! {
- Pending {
- _data: marker::PhantomData,
- }
- .await
-}
-
-impl<T> Future for Pending<T> {
- type Output = !;
-
- fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> {
- Poll::Pending
- }
-}
-
-impl<T> Unpin for Pending<T> {}
diff --git a/src/future/poll_fn.rs b/src/future/poll_fn.rs
index 9b3d137..0169bd5 100644
--- a/src/future/poll_fn.rs
+++ b/src/future/poll_fn.rs
@@ -1,3 +1,5 @@
+#![allow(dead_code)]
+
//! Definition of the `PollFn` adapter combinator
use std::fmt;
diff --git a/src/future/try_join.rs b/src/future/try_join.rs
index 5bd80dc..8943f61 100644
--- a/src/future/try_join.rs
+++ b/src/future/try_join.rs
@@ -1,4 +1,4 @@
-use crate::future::{maybe_done, MaybeDone};
+use crate::future::maybe_done::{maybe_done, MaybeDone};
use pin_project_lite::pin_project;
use std::future::Future;