File: runtime.rs

package info (click to toggle)
rust-tokio-uring 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 828 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 922 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
35
36
37
38
use tokio::net::{TcpListener, TcpStream};

#[test]
#[ignore]
fn use_tokio_types_from_runtime() {
    tokio_uring::start(async {
        let listener = TcpListener::bind("0.0.0.0:0").await.unwrap();
        let addr = listener.local_addr().unwrap();

        let task = tokio::spawn(async move {
            let _socket = TcpStream::connect(addr).await.unwrap();
        });

        // Accept a connection
        let (_socket, _) = listener.accept().await.unwrap();

        // Wait for the task to complete
        task.await.unwrap();
    });
}

#[test]
#[ignore]
fn spawn_a_task() {
    use std::cell::RefCell;
    use std::rc::Rc;

    tokio_uring::start(async {
        let cell = Rc::new(RefCell::new(1));
        let c = cell.clone();
        let handle = tokio_uring::spawn(async move {
            *c.borrow_mut() = 2;
        });

        handle.await.unwrap();
        assert_eq!(2, *cell.borrow());
    });
}