Module pendulum::future
[−]
[src]
Futures based runtime for a Pendulum
.
Heartbeat Example:
extern crate pendulum; extern crate futures; use std::time::Duration; use futures::Stream; use futures::sync::mpsc; use pendulum::HashedWheelBuilder; use pendulum::future::{TimerBuilder, TimedOut}; #[derive(Debug, PartialEq, Eq)] enum PeerMessage { KeepAlive, DoSomething } impl From<TimedOut> for PeerMessage { fn from(_: TimedOut) -> PeerMessage { PeerMessage::KeepAlive } } fn main() { // Create a timer with the default configuration let timer = TimerBuilder::default() .build(HashedWheelBuilder::default().build()); // Assume some other part of the application sends messages to some peer let (send, recv) = mpsc::unbounded(); // Application sent the peer a single message send.unbounded_send(PeerMessage::DoSomething) .unwrap(); // Wrap the receiver portion (a `Stream`), in a `Heartbeat` stream let mut heartbeat = timer.heartbeat(Duration::from_millis(100), recv) .unwrap() .wait(); // Should receive the applications message assert_eq!(PeerMessage::DoSomething, heartbeat.next().unwrap().unwrap()); // Application only sent one message, timer will continuously send keep alives // if 100 ms goes by without the original receiver receiving any messages assert_eq!(PeerMessage::KeepAlive, heartbeat.next().unwrap().unwrap()); assert_eq!(PeerMessage::KeepAlive, heartbeat.next().unwrap().unwrap()); }
Structs
Heartbeat |
|
Sleep |
|
SleepStream |
|
TimedOut |
Indicates a timeout has occurred. |
Timeout |
|
TimeoutStream |
|
Timer |
|
TimerBuilder |
Builder for configuring and constructing instances of |
TimerItem |
Item that the |
Enums
TimeoutStatus |
Convenience enum for mapping an |