Skip to content

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

@zhuxiujia

Description

@zhuxiujia

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) {
      
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-triageStatus: Waiting for a maintainer to triage this issue/PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions