File: different_executors.rs

package info (click to toggle)
rust-async-executor 1.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 252 kB
  • sloc: makefile: 2; sh: 1
file content (34 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
34
use async_executor::LocalExecutor;
use futures_lite::future::{block_on, pending, poll_once};
use futures_lite::pin;
use std::cell::Cell;

#[test]
fn shared_queue_slot() {
    block_on(async {
        let was_polled = Cell::new(false);
        let future = async {
            was_polled.set(true);
            pending::<()>().await;
        };

        let ex1 = LocalExecutor::new();
        let ex2 = LocalExecutor::new();

        // Start the futures for running forever.
        let (run1, run2) = (ex1.run(pending::<()>()), ex2.run(pending::<()>()));
        pin!(run1);
        pin!(run2);
        assert!(poll_once(run1.as_mut()).await.is_none());
        assert!(poll_once(run2.as_mut()).await.is_none());

        // Spawn the future on executor one and then poll executor two.
        ex1.spawn(future).detach();
        assert!(poll_once(run2).await.is_none());
        assert!(!was_polled.get());

        // Poll the first one.
        assert!(poll_once(run1).await.is_none());
        assert!(was_polled.get());
    });
}