2023-12-12 19:33:51 -06:00
|
|
|
//@ run-pass
|
|
|
|
//@ edition: 2024
|
|
|
|
//@ compile-flags: -Zunstable-options
|
2024-07-26 05:51:26 -05:00
|
|
|
#![feature(async_iterator, async_iter_from_iter, async_for_loop, noop_waker,
|
2023-12-12 19:33:51 -06:00
|
|
|
gen_blocks)]
|
|
|
|
|
|
|
|
async gen fn async_iter() -> i32 {
|
|
|
|
let iter = core::async_iter::from_iter(0..3);
|
|
|
|
for await i in iter {
|
|
|
|
yield i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure a simple for await loop works
|
|
|
|
async fn real_main() {
|
|
|
|
let mut count = 1;
|
|
|
|
for await i in async_iter() {
|
|
|
|
assert_eq!(i, count);
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
assert_eq!(count, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let future = real_main();
|
2024-01-14 18:25:43 -06:00
|
|
|
let mut cx = &mut core::task::Context::from_waker(std::task::Waker::noop());
|
2023-12-12 19:33:51 -06:00
|
|
|
let mut future = core::pin::pin!(future);
|
|
|
|
while let core::task::Poll::Pending = future.as_mut().poll(&mut cx) {}
|
|
|
|
}
|