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

how to Pause or Cancel when you call repo.backup() ? #339

Open
zhuxiujia opened this issue Oct 21, 2024 · 0 comments
Open

how to Pause or Cancel when you call repo.backup() ? #339

zhuxiujia opened this issue Oct 21, 2024 · 0 comments
Labels
S-triage Status: Waiting for a maintainer to triage this issue/PR

Comments

@zhuxiujia
Copy link

zhuxiujia commented Oct 21, 2024

how to Pause or Cancel when you call repo.backup() ?
I saw that the source code implementation used a blocking API.
Can you consider using tokio, as JoinHandle supports the use of asynchronous functions to forcibly cancel externally.

and.... At present, most libraries use async. If I want to support a backend myself

for example:

let handle = tokio::spawn(async{ 
            repo.backup().await
        });
        //cancel this 
        handle.abort();

currently
The way for me to cancel a task is to use panic in the inc function of Progress to stop the task

#[derive(Clone, Debug)]
pub struct MProgress {
    pub control: Arc<AtomicI32>
}

impl Progress for MProgress {
    fn is_hidden(&self) -> bool {
        false
    }
    fn set_length(&self, _len: u64) {
       
    }
    fn set_title(&self, title: &'static str) {
     
    }
    fn inc(&self, inc: u64) {
        if self.control.load(Ordering::Relaxed) == -1{
            panic!("cancel");
        }
    }
    fn finish(&self) {
      
    }
}
@github-actions github-actions bot added the S-triage Status: Waiting for a maintainer to triage this issue/PR label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-triage Status: Waiting for a maintainer to triage this issue/PR
Projects
None yet
Development

No branches or pull requests

1 participant