File: for-await-passthrough.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (27 lines) | stat: -rw-r--r-- 705 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//@ run-pass
//@ edition: 2024
#![feature(async_iterator, async_iter_from_iter, async_for_loop, 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();
    let mut cx = &mut core::task::Context::from_waker(std::task::Waker::noop());
    let mut future = core::pin::pin!(future);
    while let core::task::Poll::Pending = future.as_mut().poll(&mut cx) {}
}