Crates.io | minion |
lib.rs | minion |
version | 0.1.3 |
source | src |
created_at | 2018-05-20 18:06:05.133695 |
updated_at | 2021-07-11 17:23:08.056161 |
description | Crate for managing cancellable services |
homepage | https://github.com/jonhoo/minion |
repository | https://github.com/jonhoo/minion.git |
max_upload_size | |
id | 66364 |
size | 28,214 |
This crate provides a wrapper type for making long-running service loops cancellable.
Let's dive right in with an example. For further details see
Cancellable
.
// impl Cancellable for Service { .. }
let s = Service::new();
// start the service loop on a new thread
let h = s.spawn();
// get a handle that allows cancelling the service loop
let exit = h.canceller();
// spin up a new thread that will handle exit signals
thread::spawn(move || {
// this might catch Ctrl-C from the user, wait for a particular packet,
// or for any other condition that signals that the service should exit
// cleanly. in this case, we just terminate after a fixed amount of time.
thread::sleep(time::Duration::from_secs(1));
// tell the service loop to exit at the first opportunity
exit.cancel();
});
// block until the service loop exits or errors.
h.wait().unwrap();
The crate is under development as part of a live-coding stream series intended for users who are already somewhat familiar with Rust, and who want to see something larger and more involved be built.
You can find the recordings of past sessions in this YouTube playlist. This crate was made in this video. To get updates about future streams, follow me on Patreon or Twitter.
For each of the projects I build, I like to thank the people who are willing and able to take the extra step of supporting me in making these videos on Patreon or Liberapay. You have my most sincere gratitude, and I'm so excited that you find what I do interesting enough that you're willing to give a stranger money to do something they love!