use std::sync::mpsc::{channel, Sender}; extern crate uppercut; use std::any::Any; use std::thread::sleep; use std::time::Duration; use uppercut::api::{AnyActor, AnySender, Envelope}; use uppercut::config::{Config, SchedulerConfig}; use uppercut::core::System; use uppercut::pool::ThreadPool; #[derive(Debug)] struct Message(Option, Sender); #[derive(Default)] struct State; impl AnyActor for State { fn receive(&mut self, envelope: Envelope, sender: &mut dyn AnySender) { if let Some(msg) = envelope.message.downcast_ref::() { sender.log(&format!("received: {:?}", msg)); let x = msg.0.unwrap(); msg.1.send(x).unwrap(); } } fn on_fail(&self, _error: Box, sender: &mut dyn AnySender) { sender.log("failure detected!"); } fn on_stop(&self, sender: &mut dyn AnySender) { sender.log("shutting down"); } } fn main() { let cfg = Config::new( SchedulerConfig { eager_shutdown_enabled: false, ..Default::default() }, Default::default(), ); let sys = System::new("stop-example", "localhost", &cfg); let pool = ThreadPool::new(6); let run = sys.run(&pool).unwrap(); run.spawn_default::("x"); let (tx, rx) = channel(); run.send("x", Envelope::of(Message(Some(42), tx.clone()))); run.stop("x"); run.send("x", Envelope::of(Message(Some(100500), tx.clone()))); println!("recv: {}", rx.recv().unwrap()); sleep(Duration::from_secs(3)); run.shutdown(); }