Skip to content

Instantly share code, notes, and snippets.

@glennpratt
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save glennpratt/028de0a26eae7aeb6ba0 to your computer and use it in GitHub Desktop.

Select an option

Save glennpratt/028de0a26eae7aeb6ba0 to your computer and use it in GitHub Desktop.
Thread::spawn(move|| {
let mut eviction_lifo: Vec<(Vec<u8>, Timespec)> = vec![];
let mut timer = Timer::new().unwrap();
let validity = Duration::seconds(5);
loop {
let timeout = if eviction_lifo.len() > 1 {
let (_, arrival) = eviction_lifo[0];
let eviction_time = arrival + validity;
timer.oneshot(eviction_time - get_time())
} else {
timer.oneshot(Duration::days(1000))
};
select! (
signal = rx.recv() => {
match signal {
EvictionEntry(entry) => { eviction_lifo.push(entry); },
Quit => { break; }
}
},
() = timeout.recv() => {
let (id, _) = eviction_lifo.remove(0).unwrap();
let mut map = reaper_mutex_map.lock();
map.remove(&id);
}
)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment