archlinux / alpm.rs

Rust bindings for libalpm
GNU General Public License v3.0
112 stars 21 forks source link

Make Alpm be Send #7

Closed bluskript closed 3 years ago

bluskript commented 3 years ago

Note: I've only used Rust for a few days, so this might not make Alpm be Send.

Morganamilo commented 3 years ago

Looks good to me. The thing is though this will allow you to send alpm to another thread but it won't really help with concurruncy.

I'll merge either way because there's no reason it shouldn't be send. But if you want concurrency more will need to be done.

bluskript commented 3 years ago

What do you mean by 'it won't really help with concurrency'? Wouldn't making it Send make it possible to use alpm inside tasks? For example:

pub fn begin_proc_monitor(&self) -> Result<(), Box<dyn std::error::Error>> {
    tokio::spawn(async move {
        println!("{:?}", self.alpm);
    });
    Ok(());
}
Morganamilo commented 3 years ago

Yes you could totally do that. This will let you do something and alpm stuff concurrency. But I if you want to do multiple alpm stuff concurrent you can't.

Sync however is not safe at at. Alpm has inner multamiluty like RefCell. So relies on not being sync.