#service #cancel

minion

Crate for managing cancellable services

4 releases

Uses old Rust 2015

0.1.3 Jul 11, 2021
0.1.2 Dec 4, 2018
0.1.1 Nov 8, 2018
0.1.0 May 20, 2018

#1223 in Network programming

24 downloads per month
Used in portus

MIT/Apache

15KB
173 lines

minion

Crates.io Documentation Build Status

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();

Live-coding

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.

Thank you

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!

  • Rodrigo Valin
  • Roger Andersen (@hexjelly)
  • Pigeon F

No runtime deps