Created
March 8, 2018 16:58
-
-
Save apatrushev/0b8b5d3de310650d33f1f5a70d4e8459 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate actix; | |
extern crate tokio_core; | |
extern crate futures; | |
use std::time::Duration; | |
use futures::Stream; | |
use tokio_core::reactor::Interval; | |
use actix::prelude::*; | |
use actix::{Actor, Context, StreamHandler, SpawnHandle, Arbiter}; | |
struct ClosableActor { | |
source: SpawnHandle, | |
} | |
impl Actor for ClosableActor { | |
type Context = Context<Self>; | |
} | |
struct ClosablePacket; | |
impl<K> StreamHandler<ClosablePacket, K> for ClosableActor { | |
fn handle(&mut self, _: ClosablePacket, ctx: &mut Context<Self>) { | |
ctx.cancel_future(self.source); | |
} | |
} | |
fn main() { | |
let sys = actix::System::new("closable"); | |
let _: () = ClosableActor::create(|ctx| { | |
ClosableActor { | |
source: ctx.add_stream( | |
Interval::new( | |
Duration::from_millis(1), | |
Arbiter::handle() | |
).unwrap().map(|_| ClosablePacket) | |
), | |
} | |
}); | |
std::process::exit(sys.run()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment