about summary refs log tree commit diff
path: root/src/libstd/macros.rs
diff options
context:
space:
mode:
authorTaylor Cramer <cramertj@google.com>2018-06-06 15:50:59 -0700
committerTaylor Cramer <cramertj@google.com>2018-06-21 22:36:36 -0700
commitcf844b547dbec1f23982fca8e07ec65800ed5d6d (patch)
treea5420599dea5829f105d2a12bb14a3102141a749 /src/libstd/macros.rs
parent589446e19cbf7a2c7eddf80b490992d31134015c (diff)
async await desugaring and tests
Diffstat (limited to 'src/libstd/macros.rs')
-rw-r--r--src/libstd/macros.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index 8da70f5717e..812b0b9fdda 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -213,6 +213,26 @@ macro_rules! eprintln {
     ($fmt:expr, $($arg:tt)*) => (eprint!(concat!($fmt, "\n"), $($arg)*));
 }
 
+#[macro_export]
+#[unstable(feature = "await_macro", issue = "50547")]
+#[allow_internal_unstable]
+macro_rules! await {
+    ($e:expr) => { {
+        let mut pinned = $e;
+        let mut pinned = unsafe { ::core::mem::PinMut::new_unchecked(&mut pinned) };
+        loop {
+            match ::std::raw::with_get_cx(|cx|
+                      ::core::future::Future::poll(pinned.reborrow(), cx))
+            {
+                // FIXME(cramertj) prior to stabilizing await, we have to ensure that this
+                // can't be used to create a generator on stable via `|| await!()`.
+                ::core::task::Poll::Pending => yield,
+                ::core::task::Poll::Ready(x) => break x,
+            }
+        }
+    } }
+}
+
 /// A macro to select an event from a number of receivers.
 ///
 /// This macro is used to wait for the first event to occur on a number of