mirror of
https://github.com/async-rs/async-std.git
synced 2025-10-21 20:06:36 +00:00
feat: no to_std future::poll_fn
This commit is contained in:
parent
da23d16019
commit
94a6ff34c2
1 changed files with 9 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
||||||
use std::pin::Pin;
|
use core::future::Future;
|
||||||
use std::future::Future;
|
use core::pin::Pin;
|
||||||
|
|
||||||
use crate::task::{Context, Poll};
|
use crate::task::{Context, Poll};
|
||||||
|
|
||||||
|
@ -23,15 +23,18 @@ use crate::task::{Context, Poll};
|
||||||
/// #
|
/// #
|
||||||
/// # })
|
/// # })
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn poll_fn<F, T>(f: F) -> T
|
pub fn poll_fn<F, T>(f: F) -> PollFn<F>
|
||||||
where
|
where
|
||||||
F: FnMut(&mut Context<'_>) -> Poll<T>,
|
F: FnMut(&mut Context<'_>) -> Poll<T>,
|
||||||
{
|
{
|
||||||
let fut = PollFn { f };
|
PollFn { f }
|
||||||
fut.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PollFn<F> {
|
/// This future is constructed by the [`poll_fn`] function.
|
||||||
|
///
|
||||||
|
/// [`poll_fn`]: fn.poll_fn.html
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct PollFn<F> {
|
||||||
f: F,
|
f: F,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue