Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
parameters:
name: async_await
displayName: Async / Await
rust: nightly-2019-02-22
rust: nightly-2019-02-28
noDefaultFeatures: ''
benches: true
crates:
Expand Down
26 changes: 23 additions & 3 deletions src/async_await.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
use std::future::Future as StdFuture;
use std::pin::Pin;
use std::task::{Poll, Waker};

async fn map_ok<T: StdFuture>(future: T) -> Result<(), ()> {
let _ = await!(future);
Ok(())
fn map_ok<T: StdFuture>(future: T) -> impl StdFuture<Output = Result<(), ()>> {
MapOk(future)
}

struct MapOk<T>(T);

impl<T> MapOk<T> {
fn future<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut T> {
unsafe { Pin::map_unchecked_mut(self, |x| &mut x.0) }
}
}

impl<T: StdFuture> StdFuture for MapOk<T> {
type Output = Result<(), ()>;

fn poll(self: Pin<&mut Self>, waker: &Waker) -> Poll<Self::Output> {
match self.future().poll(waker) {
Poll::Ready(_) => Poll::Ready(Ok(())),
Poll::Pending => Poll::Pending,
}
}
}

/// Like `tokio::run`, but takes an `async` block
Expand Down
70 changes: 0 additions & 70 deletions tokio-async-await/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,77 +29,7 @@ pub mod io;
pub mod sink;
pub mod stream;

/*
pub mod prelude {
//! A "prelude" for users of the `tokio` crate.
//!
//! This prelude is similar to the standard library's prelude in that you'll
//! almost always want to import its entire contents, but unlike the standard
//! library's prelude you'll have to do so manually:
//!
//! ```
//! use tokio::prelude::*;
//! ```
//!
//! The prelude may grow over time as additional items see ubiquitous use.

pub use tokio_main::prelude::*;

#[doc(inline)]
pub use crate::async_await::{
io::{
AsyncReadExt,
AsyncWriteExt,
},
sink::{
SinkExt,
},
stream::{
StreamExt,
},
};
}
*/

// Rename the `await` macro in `std`. This is used by the redefined
// `await` macro in this crate.
#[doc(hidden)]
pub use std::await as std_await;

/*
use std::future::{Future as StdFuture};

fn run<T: futures::Future<Item = (), Error = ()>>(t: T) {
drop(t);
}

async fn map_ok<T: StdFuture>(future: T) -> Result<(), ()> {
let _ = await!(future);
Ok(())
}

/// Like `tokio::run`, but takes an `async` block
pub fn run_async<F>(future: F)
where F: StdFuture<Output = ()> + Send + 'static,
{
use async_await::compat::backward;
let future = backward::Compat::new(map_ok(future));

run(future);
unimplemented!();
}
*/

/*
/// Like `tokio::spawn`, but takes an `async` block
pub fn spawn_async<F>(future: F)
where F: StdFuture<Output = ()> + Send + 'static,
{
use crate::async_await::compat::backward;

spawn(backward::Compat::new(async || {
let _ = await!(future);
Ok(())
}));
}
*/