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

Make ctrlc::platform::block_ctrl_c() public? #47

Closed
nathan-osman opened this issue Dec 26, 2018 · 2 comments
Closed

Make ctrlc::platform::block_ctrl_c() public? #47

nathan-osman opened this issue Dec 26, 2018 · 2 comments

Comments

@nathan-osman
Copy link

Is it possible to make ctrlc::platform::block_ctrl_c() public? I am currently using a Condvar to emulate the behavior of this function and being able to use it directly would greatly simplify things:

use std::sync::{Arc, Condvar, Mutex};

let pair = Arc::new((Mutex::new(false), Condvar::new()));
let copy = pair.clone();

ctrlc::set_handler(move || {
    let &(ref lock, ref cvar) = &*copy;
    let mut started = lock.lock().unwrap();
    *started = true;
    cvar.notify_one();
})
.expect("unable to set signal handler");

let &(ref lock, ref cvar) = &*pair;

let mut started = lock.lock().unwrap();
while !*started {
    started = cvar.wait(started).unwrap();
}
@Detegr
Copy link
Owner

Detegr commented Dec 26, 2018

That could be made public, but I'm just a few minor improvements away from implementing #27 and #28, which are going to make the current API obsolete. Basically the thing you're after could be implemented with Channel like I've demonstrated in the channel example in my work-in-progress branch.

@nathan-osman
Copy link
Author

Ah, okay. Your implementation makes much more sense then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants