ump-server 0.4.1

Server message dispatch loop for ump.
Documentation
mod common;

use common::{Reply, Request, ThreadedServer};

// Terminate the dispatcher loop by dropping the only client.
#[test]
fn no_clients() {
  let (clnt, jh) =
    ump_server::spawn_thread(|_clnt| Ok(ThreadedServer {})).unwrap();

  // Drop the (only) client, which should cause dispatch loop to terminate.
  drop(clnt);

  // Termination by clients disappearing should return None
  assert_eq!(jh.join().unwrap(), None);
}

// Terminate the dispatcher loop by explicitly requesting it to terminate from
// its handler.
#[test]
fn handler_req_term() {
  let (clnt, jh) =
    ump_server::spawn_thread(|_clnt| Ok(ThreadedServer {})).unwrap();

  assert_eq!(clnt.req(Request::Add(2, 4)).unwrap(), Reply::Sum(6));
  assert_eq!(clnt.req(Request::Croak).unwrap(), Reply::OkIWillCroak);

  assert_eq!(jh.join().unwrap(), Some(42));
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :