Merge pull request #316 from k-nasa/remove_needles_main_fn

Remove needless main fn
stabilize-from-stream
Yoshua Wuyts 5 years ago committed by GitHub
commit e3e9d65bae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,7 +9,7 @@ use crate::task::{Context, Poll};
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use std::time::Duration; /// use std::time::Duration;
/// ///
@ -22,7 +22,7 @@ use crate::task::{Context, Poll};
/// let res: io::Result<()> = io::timeout(dur, fut).await; /// let res: io::Result<()> = io::timeout(dur, fut).await;
/// assert!(res.is_err()); /// assert!(res.is_err());
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub async fn pending<T>() -> T { pub async fn pending<T>() -> T {
let fut = Pending { let fut = Pending {

@ -10,7 +10,7 @@ use crate::task::{Context, Poll};
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::future; /// use async_std::future;
/// use async_std::task::{Context, Poll}; /// use async_std::task::{Context, Poll};
@ -21,7 +21,7 @@ use crate::task::{Context, Poll};
/// ///
/// assert_eq!(future::poll_fn(poll_greeting).await, "hello world"); /// assert_eq!(future::poll_fn(poll_greeting).await, "hello world");
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub async fn poll_fn<F, T>(f: F) -> T pub async fn poll_fn<F, T>(f: F) -> T
where where

@ -7,13 +7,13 @@
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::future; /// use async_std::future;
/// ///
/// assert_eq!(future::ready(10).await, 10); /// assert_eq!(future::ready(10).await, 10);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub async fn ready<T>(val: T) -> T { pub async fn ready<T>(val: T) -> T {
val val

@ -9,7 +9,7 @@ use crate::task::{Context, Poll};
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::prelude::*; /// use async_std::prelude::*;
/// use async_std::stream; /// use async_std::stream;
@ -18,7 +18,7 @@ use crate::task::{Context, Poll};
/// ///
/// assert_eq!(s.next().await, None); /// assert_eq!(s.next().await, None);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn empty<T>() -> Empty<T> { pub fn empty<T>() -> Empty<T> {
Empty { Empty {

@ -7,7 +7,7 @@
//! # Examples //! # Examples
//! //!
//! ``` //! ```
//! # fn main() { async_std::task::block_on(async { //! # async_std::task::block_on(async {
//! # //! #
//! use async_std::prelude::*; //! use async_std::prelude::*;
//! use async_std::stream; //! use async_std::stream;
@ -18,7 +18,7 @@
//! assert_eq!(v, 9); //! assert_eq!(v, 9);
//! } //! }
//! # //! #
//! # }) } //! # })
//! ``` //! ```
use cfg_if::cfg_if; use cfg_if::cfg_if;

@ -8,7 +8,7 @@ use crate::task::{Context, Poll};
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::prelude::*; /// use async_std::prelude::*;
/// use async_std::stream; /// use async_std::stream;
@ -18,7 +18,7 @@ use crate::task::{Context, Poll};
/// assert_eq!(s.next().await, Some(7)); /// assert_eq!(s.next().await, Some(7));
/// assert_eq!(s.next().await, None); /// assert_eq!(s.next().await, None);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn once<T>(t: T) -> Once<T> { pub fn once<T>(t: T) -> Once<T> {
Once { value: Some(t) } Once { value: Some(t) }

@ -8,7 +8,7 @@ use crate::task::{Context, Poll};
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::prelude::*; /// use async_std::prelude::*;
/// use async_std::stream; /// use async_std::stream;
@ -18,7 +18,7 @@ use crate::task::{Context, Poll};
/// assert_eq!(s.next().await, Some(7)); /// assert_eq!(s.next().await, Some(7));
/// assert_eq!(s.next().await, Some(7)); /// assert_eq!(s.next().await, Some(7));
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn repeat<T>(item: T) -> Repeat<T> pub fn repeat<T>(item: T) -> Repeat<T>
where where

@ -7,7 +7,7 @@
//! # Examples //! # Examples
//! //!
//! ``` //! ```
//! # fn main() { async_std::task::block_on(async { //! # async_std::task::block_on(async {
//! # //! #
//! use async_std::prelude::*; //! use async_std::prelude::*;
//! use async_std::stream; //! use async_std::stream;
@ -18,7 +18,7 @@
//! assert_eq!(v, 9); //! assert_eq!(v, 9);
//! } //! }
//! # //! #
//! # }) } //! # })
//! ``` //! ```
mod all; mod all;

@ -9,7 +9,7 @@
//! Spawn a task that updates an integer protected by a mutex: //! Spawn a task that updates an integer protected by a mutex:
//! //!
//! ``` //! ```
//! # fn main() { async_std::task::block_on(async { //! # async_std::task::block_on(async {
//! # //! #
//! use std::sync::Arc; //! use std::sync::Arc;
//! //!
@ -26,7 +26,7 @@
//! //!
//! assert_eq!(*m1.lock().await, 1); //! assert_eq!(*m1.lock().await, 1);
//! # //! #
//! # }) } //! # })
//! ``` //! ```
#[doc(inline)] #[doc(inline)]

@ -24,7 +24,7 @@ const BLOCKED: usize = 1 << 1;
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use std::sync::Arc; /// use std::sync::Arc;
/// ///
@ -46,7 +46,7 @@ const BLOCKED: usize = 1 << 1;
/// } /// }
/// assert_eq!(*m.lock().await, 10); /// assert_eq!(*m.lock().await, 10);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub struct Mutex<T> { pub struct Mutex<T> {
state: AtomicUsize, state: AtomicUsize,
@ -82,7 +82,7 @@ impl<T> Mutex<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use std::sync::Arc; /// use std::sync::Arc;
/// ///
@ -99,7 +99,7 @@ impl<T> Mutex<T> {
/// ///
/// assert_eq!(*m2.lock().await, 20); /// assert_eq!(*m2.lock().await, 20);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub async fn lock(&self) -> MutexGuard<'_, T> { pub async fn lock(&self) -> MutexGuard<'_, T> {
pub struct LockFuture<'a, T> { pub struct LockFuture<'a, T> {
@ -196,7 +196,7 @@ impl<T> Mutex<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use std::sync::Arc; /// use std::sync::Arc;
/// ///
@ -217,7 +217,7 @@ impl<T> Mutex<T> {
/// ///
/// assert_eq!(*m2.lock().await, 20); /// assert_eq!(*m2.lock().await, 20);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>> { pub fn try_lock(&self) -> Option<MutexGuard<'_, T>> {
if self.state.fetch_or(LOCK, Ordering::Acquire) & LOCK == 0 { if self.state.fetch_or(LOCK, Ordering::Acquire) & LOCK == 0 {
@ -249,7 +249,7 @@ impl<T> Mutex<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::sync::Mutex; /// use async_std::sync::Mutex;
/// ///
@ -257,7 +257,7 @@ impl<T> Mutex<T> {
/// *mutex.get_mut() = 10; /// *mutex.get_mut() = 10;
/// assert_eq!(*mutex.lock().await, 10); /// assert_eq!(*mutex.lock().await, 10);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn get_mut(&mut self) -> &mut T { pub fn get_mut(&mut self) -> &mut T {
unsafe { &mut *self.value.get() } unsafe { &mut *self.value.get() }

@ -33,7 +33,7 @@ const READ_COUNT_MASK: usize = !(ONE_READ - 1);
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::sync::RwLock; /// use async_std::sync::RwLock;
/// ///
@ -51,7 +51,7 @@ const READ_COUNT_MASK: usize = !(ONE_READ - 1);
/// *w += 1; /// *w += 1;
/// assert_eq!(*w, 6); /// assert_eq!(*w, 6);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub struct RwLock<T> { pub struct RwLock<T> {
state: AtomicUsize, state: AtomicUsize,
@ -89,7 +89,7 @@ impl<T> RwLock<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::sync::RwLock; /// use async_std::sync::RwLock;
/// ///
@ -100,7 +100,7 @@ impl<T> RwLock<T> {
/// ///
/// assert!(lock.try_read().is_some()); /// assert!(lock.try_read().is_some());
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub async fn read(&self) -> RwLockReadGuard<'_, T> { pub async fn read(&self) -> RwLockReadGuard<'_, T> {
pub struct LockFuture<'a, T> { pub struct LockFuture<'a, T> {
@ -211,7 +211,7 @@ impl<T> RwLock<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::sync::RwLock; /// use async_std::sync::RwLock;
/// ///
@ -222,7 +222,7 @@ impl<T> RwLock<T> {
/// ///
/// assert!(lock.try_read().is_some()); /// assert!(lock.try_read().is_some());
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn try_read(&self) -> Option<RwLockReadGuard<'_, T>> { pub fn try_read(&self) -> Option<RwLockReadGuard<'_, T>> {
let mut state = self.state.load(Ordering::Acquire); let mut state = self.state.load(Ordering::Acquire);
@ -253,7 +253,7 @@ impl<T> RwLock<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::sync::RwLock; /// use async_std::sync::RwLock;
/// ///
@ -264,7 +264,7 @@ impl<T> RwLock<T> {
/// ///
/// assert!(lock.try_read().is_none()); /// assert!(lock.try_read().is_none());
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub async fn write(&self) -> RwLockWriteGuard<'_, T> { pub async fn write(&self) -> RwLockWriteGuard<'_, T> {
pub struct LockFuture<'a, T> { pub struct LockFuture<'a, T> {
@ -374,7 +374,7 @@ impl<T> RwLock<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::sync::RwLock; /// use async_std::sync::RwLock;
/// ///
@ -385,7 +385,7 @@ impl<T> RwLock<T> {
/// ///
/// assert!(lock.try_write().is_none()); /// assert!(lock.try_write().is_none());
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> { pub fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> {
let mut state = self.state.load(Ordering::Acquire); let mut state = self.state.load(Ordering::Acquire);
@ -431,7 +431,7 @@ impl<T> RwLock<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::sync::RwLock; /// use async_std::sync::RwLock;
/// ///
@ -439,7 +439,7 @@ impl<T> RwLock<T> {
/// *lock.get_mut() = 10; /// *lock.get_mut() = 10;
/// assert_eq!(*lock.write().await, 10); /// assert_eq!(*lock.write().await, 10);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn get_mut(&mut self) -> &mut T { pub fn get_mut(&mut self) -> &mut T {
unsafe { &mut *self.value.get() } unsafe { &mut *self.value.get() }

@ -31,11 +31,9 @@ use kv_log_macro::trace;
/// ```no_run /// ```no_run
/// use async_std::task; /// use async_std::task;
/// ///
/// fn main() { /// task::block_on(async {
/// task::block_on(async { /// println!("Hello, world!");
/// println!("Hello, world!"); /// })
/// })
/// }
/// ``` /// ```
pub fn block_on<F, T>(future: F) -> T pub fn block_on<F, T>(future: F) -> T
where where

@ -10,7 +10,7 @@
//! Spawn a task and await its result: //! Spawn a task and await its result:
//! //!
//! ``` //! ```
//! # fn main() { async_std::task::block_on(async { //! # async_std::task::block_on(async {
//! # //! #
//! use async_std::task; //! use async_std::task;
//! //!
@ -19,7 +19,7 @@
//! }); //! });
//! assert_eq!(handle.await, 3); //! assert_eq!(handle.await, 3);
//! # //! #
//! # }) } //! # })
//! ``` //! ```
#[doc(inline)] #[doc(inline)]
@ -64,7 +64,7 @@ pub(crate) mod blocking;
/// Basic usage: /// Basic usage:
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::task; /// use async_std::task;
/// ///
@ -72,7 +72,7 @@ pub(crate) mod blocking;
/// println!("long-running task here"); /// println!("long-running task here");
/// }).await; /// }).await;
/// # /// #
/// # }) } /// # })
/// ``` /// ```
// Once this function stabilizes we should merge `blocking::spawn` into this so // Once this function stabilizes we should merge `blocking::spawn` into this so
// all code in our crate uses `task::blocking` too. // all code in our crate uses `task::blocking` too.

@ -22,7 +22,7 @@ use crate::utils::abort_on_panic;
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::task; /// use async_std::task;
/// ///
@ -32,7 +32,7 @@ use crate::utils::abort_on_panic;
/// ///
/// assert_eq!(handle.await, 3); /// assert_eq!(handle.await, 3);
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn spawn<F, T>(future: F) -> JoinHandle<T> pub fn spawn<F, T>(future: F) -> JoinHandle<T>
where where

@ -14,7 +14,7 @@ use crate::io;
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use std::time::Duration; /// use std::time::Duration;
/// ///
@ -22,7 +22,7 @@ use crate::io;
/// ///
/// task::sleep(Duration::from_secs(1)).await; /// task::sleep(Duration::from_secs(1)).await;
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub async fn sleep(dur: Duration) { pub async fn sleep(dur: Duration) {
let _: io::Result<()> = io::timeout(dur, future::pending()).await; let _: io::Result<()> = io::timeout(dur, future::pending()).await;

@ -68,7 +68,7 @@ impl<T> JoinHandle<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::task; /// use async_std::task;
/// ///
@ -77,7 +77,7 @@ impl<T> JoinHandle<T> {
/// }); /// });
/// println!("id = {}", handle.task().id()); /// println!("id = {}", handle.task().id());
/// # /// #
/// # }) } /// # })
pub fn task(&self) -> &Task { pub fn task(&self) -> &Task {
self.0.tag().task() self.0.tag().task()
} }

@ -22,13 +22,13 @@ use crate::utils::abort_on_panic;
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # fn main() { async_std::task::block_on(async { /// # async_std::task::block_on(async {
/// # /// #
/// use async_std::task; /// use async_std::task;
/// ///
/// println!("The name of this task is {:?}", task::current().name()); /// println!("The name of this task is {:?}", task::current().name());
/// # /// #
/// # }) } /// # })
/// ``` /// ```
pub fn current() -> Task { pub fn current() -> Task {
get_task(|task| task.clone()).expect("`task::current()` called outside the context of a task") get_task(|task| task.clone()).expect("`task::current()` called outside the context of a task")

Loading…
Cancel
Save