rethinkdb / rethinkdb-rs

A native RethinkDB driver written in Rust
Apache License 2.0
210 stars 27 forks source link

Aborting a call to changes() somehow. #41

Closed TotalKrill closed 3 years ago

TotalKrill commented 5 years ago

Hi again

So I ran into another issue, which i cannot seem to figure out. I want to listen for changes to a table, but only for a while, then I want to stop and do other things.

Looking at the code I found that there is Response.poll() , which should return a status, my plan was to use that and poll for data, getting the data when possible, or otherwise just timeout after enough time had passed, this way i could offload checking the entire table for changes to the data.

So i tried this, and it compiles:

    let r = Client::new();
    // Create a connection pool
    println!("Connecting");
    let conn = r.connect(conf).unwrap();

    let now = Instant::now();

    let mut query = r.db("rethinkdb")
        .table("server_status")
        .changes()
        .run::<Change<ServerStatus, ServerStatus>>(conn).unwrap();

    loop {
        println!("loop");

        match query.poll() {
            Ok(n) => {
                println!("{:?}", n);
            },
            _ => break,
        }
        if now.elapsed().as_secs() > 30 {
            break;
        }
    }

But it crashes with:

thread 'main' panicked at 'no Task is currently running', libcore/option.rs:1010:5

rushmorem commented 5 years ago

You shouldn't poll futures directly like that. Try futures-timer instead.

rushmorem commented 3 years ago

See https://github.com/rethinkdb/rethinkdb-rs/issues/57#issuecomment-832336662