A little fairer
This commit is contained in:
parent
5db05b2df2
commit
a401e5fcd1
|
@ -5,7 +5,7 @@ use std::sync::atomic::Ordering;
|
||||||
|
|
||||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
|
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
|
||||||
|
|
||||||
type Ref<T> = UnboundedSender<T>;
|
type Ref<T> = UnboundedSender<Box<T>>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Instruction {
|
enum Instruction {
|
||||||
|
@ -35,14 +35,14 @@ trait Actor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send<T: std::marker::Send + 'static>(ch: &Arc<Ref<T>>, message: T) -> () {
|
fn send<T: std::marker::Send + 'static>(ch: &Arc<Ref<T>>, message: T) -> () {
|
||||||
match ch.send(message) {
|
match ch.send(Box::new(message)) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(v) => panic!("Aiee! Could not send {:?}", v),
|
Err(v) => panic!("Aiee! Could not send {:?}", v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn<T: std::marker::Send + 'static, R: Actor<T> + std::marker::Send + 'static>(rt: Option<Arc<AtomicU64>>, mut ac: R) -> Arc<Ref<T>> {
|
fn spawn<T: std::marker::Send + 'static, R: Actor<T> + std::marker::Send + 'static>(rt: Option<Arc<AtomicU64>>, mut ac: R) -> Arc<Ref<T>> {
|
||||||
let (tx, mut rx) = unbounded_channel();
|
let (tx, mut rx) = unbounded_channel::<Box<T>>();
|
||||||
if let Some(ref c) = rt {
|
if let Some(ref c) = rt {
|
||||||
c.fetch_add(1, Ordering::SeqCst);
|
c.fetch_add(1, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ fn spawn<T: std::marker::Send + 'static, R: Actor<T> + std::marker::Send + 'stat
|
||||||
match rx.recv().await {
|
match rx.recv().await {
|
||||||
None => break,
|
None => break,
|
||||||
Some(message) => {
|
Some(message) => {
|
||||||
match ac.message(message) {
|
match ac.message(*message) {
|
||||||
Action::Continue => continue,
|
Action::Continue => continue,
|
||||||
Action::Stop => break,
|
Action::Stop => break,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue