mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-30 19:54:36 +01:00
45 lines
926 B
Rust
45 lines
926 B
Rust
//! Derived from this comment:
|
|
//! https://github.com/actix/actix/issues/464#issuecomment-779427825
|
|
|
|
use std::{thread, time::Duration};
|
|
|
|
use actix_rt::{Arbiter, System};
|
|
use tokio::sync::mpsc;
|
|
|
|
#[test]
|
|
fn actix_sample() {
|
|
let sys = System::new();
|
|
let arb = Arbiter::new();
|
|
|
|
let (_tx, mut rx) = mpsc::unbounded_channel::<()>();
|
|
|
|
// create "actor"
|
|
arb.spawn_fn(move || {
|
|
let a = A;
|
|
|
|
actix_rt::spawn(async move {
|
|
while let Some(_) = rx.recv().await {
|
|
println!("{:?}", a);
|
|
}
|
|
});
|
|
});
|
|
|
|
System::current().stop();
|
|
|
|
// all arbiters must be dropped when sys.run returns
|
|
sys.run().unwrap();
|
|
|
|
thread::sleep(Duration::from_millis(100));
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
struct A;
|
|
|
|
impl Drop for A {
|
|
fn drop(&mut self) {
|
|
println!("start drop");
|
|
thread::sleep(Duration::from_millis(200));
|
|
println!("finish drop");
|
|
}
|
|
}
|