Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable auto resume in RowIterator #162

Merged
merged 5 commits into from Jun 13, 2023
Merged

Add option to disable auto resume in RowIterator #162

merged 5 commits into from Jun 13, 2023

Conversation

yoshidan
Copy link
Owner

@yoshidan yoshidan commented Jun 12, 2023

This PR will fix #158.

If the future can be dropped by tokio::select or other methods when searching for a change stream, the resume process after an error occurs in stream.message() will remain in the Pending state forever. enable_resume=false in QueryOption to immediately return an error without performing the resume process.

async fn query(client: Client) {
    let mut tx = client.single().await.unwrap();
    let option = QueryOptions {
        enable_resume: false,
        ..Default::default()
    };
    let mut stmt = Statement::new("SELECT ChangeRecord FROM READ_UserItemChangeStream (
           start_timestamp => @now,
           end_timestamp => NULL,
           partition_token => {},
           heartbeat_milliseconds => 10000
     )");
    stmt.add_param("now", &OffsetDateTime::now_utc());
    let mut rows = tx.query_with_option(stmt, option).await.unwrap();
    let mut tick = tokio::time::interval(tokio::time::Duration::from_millis(100));
    loop {
          tokio::select! {
                 _ = tick.tick() => {
                      // run task
                 },
                 maybe = rows.next() =>  {
                      let row = maybe.unwrap().unwrap();
                 }
           }
     }
}

@yoshidan yoshidan added the safe to test safe to test label Jun 12, 2023
@yoshidan yoshidan added safe to test safe to test and removed safe to test safe to test labels Jun 12, 2023
@yoshidan yoshidan merged commit 51994b1 into main Jun 13, 2023
7 of 8 checks passed
@yoshidan yoshidan deleted the issue158 branch June 13, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test safe to test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RowIterator+AsyncIterator are not cancellation safe
1 participant