Skip to content

Commit

Permalink
Get rid of LISTENERS static
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Sep 22, 2022
1 parent 7205ed8 commit c0b84b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
16 changes: 0 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,10 @@ const PERIOD_BLOCKS: u64 = 2016;
const CYCLE_EPOCHS: u64 = 6;

static INTERRUPTS: AtomicU64 = AtomicU64::new(0);
static LISTENERS: Mutex<Vec<Handle>> = Mutex::new(Vec::new());

fn main() {
env_logger::init();

ctrlc::set_handler(move || {
LISTENERS
.lock()
.unwrap()
.iter()
.for_each(|handle| handle.graceful_shutdown(Some(Duration::from_millis(100))));

let interrupts = INTERRUPTS.fetch_add(1, atomic::Ordering::Relaxed);

if interrupts > 5 {
process::exit(1);
}
})
.expect("Error setting ctrl-c handler");

if let Err(err) = Arguments::parse().run() {
eprintln!("error: {}", err);
err
Expand Down
16 changes: 15 additions & 1 deletion src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,21 @@ impl Subcommand {
Self::Server(server) => {
let index = Arc::new(Index::open(&options)?);
let handle = Handle::new();
LISTENERS.lock().unwrap().push(handle.clone());

{
let handle = handle.clone();
ctrlc::set_handler(move || {
handle.graceful_shutdown(Some(Duration::from_millis(100)));

let interrupts = INTERRUPTS.fetch_add(1, atomic::Ordering::Relaxed);

if interrupts > 5 {
process::exit(1);
}
})
.expect("Error setting ctrl-c handler");
}

server.run(options, index, handle)
}
Self::Supply => supply::run(),
Expand Down

0 comments on commit c0b84b2

Please sign in to comment.